cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
TL5866 Frequent Visitor
Frequent Visitor

Inconsistent results in DAX: SUMX() on DISTINCTCOUNT() w/o SortOrder

Hi,

 

I'm using the follwing formula:

Measure = SUMX(VALUES('Table'[Type]), CALCULATE(DISTINCTCOUNT('Table'[Color])))

on the following table:

 

CategoryColorTypeSortOrderTypeSize
cat1red1A22
cat1red1A24
cat1blue1A22
cat1yellow2B24
cat1red2B24
cat1blue1A26
cat1blue2B28
cat1yellow2B22
cat1red1A24
cat1blue1A24
cat2yellow1A22
cat2black1A24
cat2blue1A22
cat2red2B24
cat2blue2B22
cat2yellow3C24

 

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

2018-06-01 14_05_13-SUMX on DistinctCount - Power BI Desktop.png

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 ?

2018-06-01 13_53_28-SUMX on DistinctCount - Power BI Desktop.png

Here is the link to the PBIX:

https://drive.google.com/file/d/1N26gmBa3Apo-W7oDlpYBLXERhhBpoq8V/view?usp=sharing

 

Thanks

 

Thierry

1 ACCEPTED SOLUTION

Accepted Solutions
Thejeswar Senior Member
Senior Member

Re: Inconsistent results in DAX: SUMX() on DISTINCTCOUNT() w/o SortOrder

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

Output-DistinctCOUNT.PNG

 

 

I think this is what your expected output is!!!

 

Regards,

Thejeswar

 

 

 

 

View solution in original post

4 REPLIES 4
Moderator v-qiuyu-msft
Moderator

Re: Inconsistent results in DAX: SUMX() on DISTINCTCOUNT() w/o SortOrder

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 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thejeswar Senior Member
Senior Member

Re: Inconsistent results in DAX: SUMX() on DISTINCTCOUNT() w/o SortOrder

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

Output-DistinctCOUNT.PNG

 

 

I find the values to be appropriate (as expected).

 

The Measure formula that is used is 

 

Measure = DISTINCTCOUNT(Table1[Color]) 

Regards,

Thejeswar

TL5866 Frequent Visitor
Frequent Visitor

Re: Inconsistent results in DAX: SUMX() on DISTINCTCOUNT() w/o SortOrder

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:

  • Type A contains (blue, red) -> Sum for Type A = 2
  • Type B contains (red, yellow) -> Sum for Type B = 2
  • Cat1 contains (Type A, Type B) -> Sum for Cat1 = 2+2 = 4

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...

Thejeswar Senior Member
Senior Member

Re: Inconsistent results in DAX: SUMX() on DISTINCTCOUNT() w/o SortOrder

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

Output-DistinctCOUNT.PNG

 

 

I think this is what your expected output is!!!

 

Regards,

Thejeswar

 

 

 

 

View solution in original post

Helpful resources

Announcements
New Kudos Received Badges Coming

New Kudos Received Badges Coming

Kudos to you if you earned one of these! Check your inbox for a notification.

Microsoft Implementation for Communities Wins Award

Microsoft Implementation for Communities Wins Award

Learn about the award-winning innovation that was implemented across Microsoft’s Business Applications Communities.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Kudoed Authors (Last 30 Days)
Users online (1,322)