Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon'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.
Hello.
I have the following table for benchmarks of height in inches:
Lets say I'm calculating the number of dogs that fall under each of the category using the following formula:
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.
Solved! Go to Solution.
Right, makes sense.
To model it "correctly", I'd probably do this with the Benchmark Categories.
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 ;). |
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. | Proud to be a Super User! |
Right, makes sense.
To model it "correctly", I'd probably do this with the Benchmark Categories.
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 ;). |
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. | Proud to be a Super User! |
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 ;). |
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. | Proud to be a 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.
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 ;). |
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. | Proud to be a Super User! |
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 ;). |
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. | Proud to be a Super User! |
There is no relationship.
I created a custom example. Essentially I have 2 tables:
Benchmark Categories:
Dogs:
However, I still miss the 11-20 category:
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
120 | |
78 | |
47 | |
38 | |
31 |
User | Count |
---|---|
192 | |
79 | |
70 | |
50 | |
42 |