Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
Check it out now!Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
Hi,
I'm using the follwing formula:
Measure = SUMX(VALUES('Table'[Type]), CALCULATE(DISTINCTCOUNT('Table'[Color])))
on the following table:
Category | Color | TypeSortOrder | Type | Size |
cat1 | red | 1 | A | 22 |
cat1 | red | 1 | A | 24 |
cat1 | blue | 1 | A | 22 |
cat1 | yellow | 2 | B | 24 |
cat1 | red | 2 | B | 24 |
cat1 | blue | 1 | A | 26 |
cat1 | blue | 2 | B | 28 |
cat1 | yellow | 2 | B | 22 |
cat1 | red | 1 | A | 24 |
cat1 | blue | 1 | A | 24 |
cat2 | yellow | 1 | A | 22 |
cat2 | black | 1 | A | 24 |
cat2 | blue | 1 | A | 22 |
cat2 | red | 2 | B | 24 |
cat2 | blue | 2 | B | 22 |
cat2 | yellow | 3 | C | 24 |
In modeling, Type is set as sorted by TypeSortOrder. I set a visual (or page or report) filter on (Category = cat1) and (Size=22 or Size=24).
Then I'm showing the measure in a matrix visual - all fine
If I remove the sorting on Type and turn it back to default, here is what I get - values for Color and Type are incorrect.
Can you help understand why ? Is it the expected behavior ?
Here is the link to the PBIX:
https://drive.google.com/file/d/1N26gmBa3Apo-W7oDlpYBLXERhhBpoq8V/view?usp=sharing
Thanks
Thierry
Solved! Go to Solution.
Hi @TL5866,
Try using the below measure
I am using an additional column called Concatenated whose expression is
Concatenated = CONCATENATE(Table1[Type],Table1[Color])
and the Measure is
Measure = IF(HASONEVALUE(Table1[Color]),DISTINCTCOUNT(Table1[Color]),IF(HASONEVALUE(Table1[Type]),DISTINCTCOUNT(Table1[Color]),IF(HASONEVALUE(Table1[Category]),DISTINCTCOUNT(Table1[Concatenated]))))
My Output is
I think this is what your expected output is!!!
Regards,
Thejeswar
Hi,
Thanks for your replies. Your results are correct, but this does not match the case that I'm trying to solve here.
I am using SUMX() over Type because I want the Category to be the sum of distinct Colors within one Type at the time. So using my formula with SUMX() gives the following result:
Using CALCULATE() with VALUES(), or simply DISTINCTCOUNT() simply does not give the correct result. In that case, the total for Cat is 3 (blue, red, yellow), because, one of the colors is the same across Type. So it does not solve the issue actually...
Hi @TL5866,
Try using the below measure
I am using an additional column called Concatenated whose expression is
Concatenated = CONCATENATE(Table1[Type],Table1[Color])
and the Measure is
Measure = IF(HASONEVALUE(Table1[Color]),DISTINCTCOUNT(Table1[Color]),IF(HASONEVALUE(Table1[Type]),DISTINCTCOUNT(Table1[Color]),IF(HASONEVALUE(Table1[Category]),DISTINCTCOUNT(Table1[Concatenated]))))
My Output is
I think this is what your expected output is!!!
Regards,
Thejeswar
Hi @TL5866,
The Values won't generally get affected by the Columns that we use for sorting
I tried your case with your data assuming that you are trying to find the Distinct Count of Value Column (in this case color) for your attributes (category, Type and Color) and the output screenshot is as below
I find the values to be appropriate (as expected).
The Measure formula that is used is
Measure = DISTINCTCOUNT(Table1[Color])
Regards,
Thejeswar
Hi @TL5866,
Do you want to calculate distinct count rows within category, Size and Color group, right?
If it does, you need to modify the measure as below:
Measure = CALCULATE(DISTINCTCOUNT('Table'[Color]),VALUES('Table'[Category]))
The value will not change whether we set Type column sort by default or TypeSoryOrder column.
For detail information, see this new report: https://www.dropbox.com/s/4fwdr404zbxjnre/SUMX%20on%20DistinctCount.pbix?dl=0
Best Regards,
Qiuyun Yu