Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
MikhailGG
Frequent Visitor

How to show every category in the chart, not only the ones that have values in them?

Hello.

 

I have the following table for benchmarks of height in inches: 

MikhailGG_0-1730389655446.png

Lets say I'm calculating the number of dogs that fall under each of the category using the following formula:

Dogs_height =
dogs = Table['dogs']
    return CALCULATE (VALUES ( 'Benchmark Categories'[Categories]), dogs>='Benchmark Categories'[Lower_Level],dogs<='Benchmark Categories'[Upper_Level])
 
The issue with that is that I'm getting the results only for those that fall under any of the categories, but if there are no values for any specific category, then I get nothing.
MikhailGG_1-1730389894790.png

What I would like to get is all of the categories in the chart, but when there is no values in any particular category, then show it as 0 rather than not including it. E.g. 121-130 category will have 0, so as 141-150, etc.

1 ACCEPTED SOLUTION
KNP
Super User
Super User

Right, makes sense.

To model it "correctly", I'd probably do this with the Benchmark Categories.

 

KNP_0-1730400329241.png

 

Here's the code for reference...

 

let
    // Source data from a compressed Base64 JSON string
    Source = 
        Table.FromRows(
            Json.Document(
                Binary.Decompress(
                    Binary.FromText(
                        "i45WMlDSUTI0UIrViVYyNASyjSBsIxDbGMI2BrFNIGwTENsUyI4FAA==", 
                        BinaryEncoding.Base64
                    ), 
                    Compression.Deflate
                )
            ), 
            let
                _t = ((type nullable text) meta [Serialized.Text = true])
            in
                type table [#"Lower Level" = _t, #"Upper Level" = _t]
        ),
    
    // Add a custom column "Categories"
    AddedCategories = 
        Table.AddColumn(
            Source, 
            "Categories", 
            each [Lower Level] & "-" & [Upper Level]
        ),
    
    // Add an index column
    AddedIndex = 
        Table.AddIndexColumn(
            AddedCategories, 
            "Index", 
            1, 
            1, 
            Int64.Type
        ),
    
    // Change column types
    ChangedType = 
        Table.TransformColumnTypes(
            AddedIndex, 
            {
                {"Lower Level", Int64.Type}, 
                {"Upper Level", Int64.Type}, 
                {"Categories", type text}
            }
        ),
    
    // Add a custom column "Height" with a list of numbers from Lower Level to Upper Level
    AddedHeight = 
        Table.AddColumn(
            ChangedType, 
            "Height", 
            each {Number.From([Lower Level])..Number.From([Upper Level])}
        ),
    
    // Expand the list in the "Height" column
    ExpandedHeight = 
        Table.ExpandListColumn(
            AddedHeight, 
            "Height"
        ),
    
    // Change the type of the "Height" column to Int64
    ChangedTypeHeight = 
        Table.TransformColumnTypes(
            ExpandedHeight, 
            {{"Height", Int64.Type}}
        )
in
    ChangedTypeHeight

 

Once you have that table exploded, join Height to the height in dogs and then use the Categories column from the Benchmark table in your visual and the method I mentioned previously to ensure all categories show. 

It will likely also help simplify the DAX required.

 

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

View solution in original post

7 REPLIES 7
KNP
Super User
Super User

Right, makes sense.

To model it "correctly", I'd probably do this with the Benchmark Categories.

 

KNP_0-1730400329241.png

 

Here's the code for reference...

 

let
    // Source data from a compressed Base64 JSON string
    Source = 
        Table.FromRows(
            Json.Document(
                Binary.Decompress(
                    Binary.FromText(
                        "i45WMlDSUTI0UIrViVYyNASyjSBsIxDbGMI2BrFNIGwTENsUyI4FAA==", 
                        BinaryEncoding.Base64
                    ), 
                    Compression.Deflate
                )
            ), 
            let
                _t = ((type nullable text) meta [Serialized.Text = true])
            in
                type table [#"Lower Level" = _t, #"Upper Level" = _t]
        ),
    
    // Add a custom column "Categories"
    AddedCategories = 
        Table.AddColumn(
            Source, 
            "Categories", 
            each [Lower Level] & "-" & [Upper Level]
        ),
    
    // Add an index column
    AddedIndex = 
        Table.AddIndexColumn(
            AddedCategories, 
            "Index", 
            1, 
            1, 
            Int64.Type
        ),
    
    // Change column types
    ChangedType = 
        Table.TransformColumnTypes(
            AddedIndex, 
            {
                {"Lower Level", Int64.Type}, 
                {"Upper Level", Int64.Type}, 
                {"Categories", type text}
            }
        ),
    
    // Add a custom column "Height" with a list of numbers from Lower Level to Upper Level
    AddedHeight = 
        Table.AddColumn(
            ChangedType, 
            "Height", 
            each {Number.From([Lower Level])..Number.From([Upper Level])}
        ),
    
    // Expand the list in the "Height" column
    ExpandedHeight = 
        Table.ExpandListColumn(
            AddedHeight, 
            "Height"
        ),
    
    // Change the type of the "Height" column to Int64
    ChangedTypeHeight = 
        Table.TransformColumnTypes(
            ExpandedHeight, 
            {{"Height", Int64.Type}}
        )
in
    ChangedTypeHeight

 

Once you have that table exploded, join Height to the height in dogs and then use the Categories column from the Benchmark table in your visual and the method I mentioned previously to ensure all categories show. 

It will likely also help simplify the DAX required.

 

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
MikhailGG
Frequent Visitor

That worked. Thanks.

 

Follow up question:

What if I want to use the same field heights and measure other fields in the same table? 

Originaly it was height, but what if I'll include weight and age fields to the dog table. How do I make a relationship if I want to use the same benchmark table and same "Height field" to measure weight and age in addition to heigh?.

Honestly, I was focussed on solving the initial problem. Is it working? I thought I saw a message from you saying it's not?

 

To answer your follow-up, without looking at the full picture, I'm not sure how I would model it. You can create buckets for reporting and may not need the dimension tables but I prefer to create the dimensions as it makes the reporting and DAX easier.

 

I probably wouldn't try to keep it all in the same benchmark table and may create new versions for weight and age and join to the dog table, but like I say, without having the full picture, it's hard to say.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
KNP
Super User
Super User

If I understand correctly, if you right click on one of your fields in the field well, you can turn on 'Show items with no data'. I think that'll give you what you're looking for.

 

KNP_0-1730395426087.png

 

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
MikhailGG
Frequent Visitor

Hi @KNP 

 

I tried that but it does nothing.

It's like it only accounts for the data in the categories.

Can you add a screenshot of your data model/relationships?

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
MikhailGG
Frequent Visitor

There is no relationship.

MikhailGG_3-1730397518911.png

 

I created a custom example. Essentially I have 2 tables:

Benchmark Categories:

MikhailGG_2-1730397502219.png

 

Dogs: 

MikhailGG_1-1730397473424.png

 

However, I still miss the 11-20 category:

MikhailGG_4-1730397585937.png

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.