Results 1 to 8 of 8
  1. #1
    vinaynaran is offline Novice
    Windows 11 Office 365
    Join Date
    Oct 2025
    Posts
    1

    Do not display column when total is zeo

    Hi all,

    Part Branch1 Branch2 Branch3 Branch4 Branch5 Branch6
    2345 23 9 0 97 0 7
    45667 5 7 0 5 0 5
    78855 6 0 0 4 0 4
    55776 7 8 0 32 0 34
    45790 7 9 0 24 0 2
    45664 1 87 0 2 0 90
    49 120 0 164 0 142

    I have a table like above and I would like to create query where any branch total is ZERO do not display in output result like below.

    in short I want below output result from above table.

    Part Branch1 Branch2 Branch4 Branch6
    2345 23 9 97 7
    45667 5 7 5 5
    78855 6 0 4 4
    55776 7 8 32 34
    45790 7 9 24 2
    45664 1 87 2 90

    Please advise.


    Thanks
    Vinay

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,929
    If your data was properly normalised, it would not be a problem- you would simply use a crosstab query to display the data. As it is you would need some complex vba code to determine the zero columns and then hide or remove the column and then move the columns to the right, left to hide the gap

    manually in a datasheet you could do this by right clicking on the header and select hide. Can also be done in vba by setting the column width property to 0

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,553
    I would create a count for each branch for each record.
    If a branch count of zero for a branch equals the record count, then omit that branch.

    So you need to pre process the data first, then amend the sql to remove the column(s).

    Normalise your data and it would be so much easier, as mentioned.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    jojowhite's Avatar
    jojowhite is online now Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    433
    what you will be needing is a VBA to build your query.
    then you need a form to display the resulting query (see SampleForm on the demo).
    see the code that create the query in Module1.
    Attached Files Attached Files

  5. #5
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,820
    Hi Vinay

    Attached is an example of how you should construct your tables.
    Attached Files Attached Files

  6. #6
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,820
    In my example database you would need to run the "qryAllFields_Crosstab" to show the desired output.

    To get the Totals for each Column you would run a Report based on this query.

  7. #7
    Join Date
    Sep 2025
    Location
    Newport, Shropshire, UK
    Posts
    18
    Unfortunately, by having multiple columns for the branches, your table is 'encoding data as column headings'. A fundamental principle of the database relational model is the Information Principle (Codd's Rule #1). This requires that all data be stored as single values at column positions in rows in tables, and in no other way. The attached file illustrates how data incorrectly modelled in this way can be corrected by means of VBA code which inserts data into a pre-defined table which models the many to many relationship type. In the demo the 'Quantity in Stock Values' option is appropriate to your database.
    Attached Files Attached Files

  8. #8
    madpiet is online now Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    565
    Quote Originally Posted by Ken Sheridan View Post
    Unfortunately, by having multiple columns for the branches, your table is 'encoding data as column headings'. A fundamental principle of the database relational model is the Information Principle (Codd's Rule #1). This requires that all data be stored as single values at column positions in rows in tables, and in no other way. The attached file illustrates how data incorrectly modelled in this way can be corrected by means of VBA code which inserts data into a pre-defined table which models the many to many relationship type. In the demo the 'Quantity in Stock Values' option is appropriate to your database.
    This is where I like to resort to Excel. (Yeah, I know!) but I can do an unpivot in PowerQuery and it's done.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 04-11-2024, 05:04 AM
  2. Replies: 14
    Last Post: 07-13-2015, 12:47 PM
  3. Want to update a column A if column B = column C
    By AudiA4_20T in forum Queries
    Replies: 5
    Last Post: 08-08-2012, 02:42 PM
  4. Replies: 1
    Last Post: 12-08-2011, 08:03 AM
  5. Replies: 7
    Last Post: 04-27-2010, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums