cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Anonymous
Not applicable

## Wrong total sum, distinct count

I have this table:

I want to show only those brands with more than 2 distinct articles.

This measure works fine for all the numbers in the table, but total sum fails.

I was not able to adapt for Greg's solution.

Is there a DAX formula to do so?

2 ACCEPTED SOLUTIONS
Super User

I believe you want something like this, should have the right total:

``````Measure 2 =
VAR __Sales =
SUMMARIZE(articles,[Brand],"__Sales",SUM([Sales]),"__Count",COUNTX(DISTINCT(SUMMARIZE(articles,[Articles])),[Articles]))
RETURN
SUMX(FILTER(__Sales,[__Count]>2),[__Sales])``````

See attached, Page 2, articles table.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Super User

Hi,

Try these measures

``Total sales = SUM(Data[Sales])``
``Number of articles = DISTINCTCOUNT(Data[Articles])``
``Measure = SUMX(FILTER(SUMMARIZE(VALUES(Data[Brand]),Data[Brand],"ABCD",[Number of articles],"EFGH",[Total sales]),[ABCD]>2),[EFGH])``

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
12 REPLIES 12
Super User
Can you post that raw data as text and can you also post your expected result of your sample data?

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Brand;Articles;Sales
A;Article1;4
A;Article2;2
A;Article1;2
A;Article1;5
B;Article3;10
B;Article3;105
B;Article3;26
C;Article1;24
C;Article2;27
C;Article3;85
C;Article4;63
D;Article5;15
D;Article5;45
E;Article5;65
E;Article2;35
E;Article2;85
E;Article2;91
E;Article1;10

Anonymous
Not applicable

Should be the result

Super User

Hi,

Try these measures

``Total sales = SUM(Data[Sales])``
``Number of articles = DISTINCTCOUNT(Data[Articles])``
``Measure = SUMX(FILTER(SUMMARIZE(VALUES(Data[Brand]),Data[Brand],"ABCD",[Number of articles],"EFGH",[Total sales]),[ABCD]>2),[EFGH])``

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Anonymous
Not applicable

@Ashish_Mathur: That works perfectly! That means, there has to be an intermediate table to filter on, makes sense.

Super User

You are welcome.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Super User

@Anonymous try this measure

``````Sum of distinct count =
SUMX ( VALUES ( Table[Brand] ), [Z_DistCount] )``````

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Thank you, parry2k, but gives me not the correct result.

Super User

I believe you want something like this, should have the right total:

``````Measure 2 =
VAR __Sales =
SUMMARIZE(articles,[Brand],"__Sales",SUM([Sales]),"__Count",COUNTX(DISTINCT(SUMMARIZE(articles,[Articles])),[Articles]))
RETURN
SUMX(FILTER(__Sales,[__Count]>2),[__Sales])``````

See attached, Page 2, articles table.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler: This is very neat, too. Thank you, Greg. So the part where you state

``COUNTX(DISTINCT(SUMMARIZE(``

caters for older version of Power BI, am I right? The younger formula

``DISTINCTCOUNT()``

makes it shorter than before, correct?

Super User

Unless it has changed recently, DISTINCTCOUNT only accepts an actual column in an actual table as a parameter. Thus, if we are working with a table expression, we cannot use DISTINCTCOUNT and have to essentially code around it in the manner shown. There is no DISTINCTCOUNTX function like there is COUNTX so we have to work around that.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler : I adapted your formula with DISTINCTCOUNT, and it seemed to work.

``````Gregs_Measure_adapted =
var _Sales = SUMMARIZE(Table1;Table1[Brand];"_Sales_";SUM(Table1[Sales]); "_Count_"; DISTINCTCOUNT(Table1[Articles]))
Return
SUMX(FILTER(_Sales;[_Count_]>2);[_Sales_])``````

Do you think, it worked due to the special, simple design of the table?

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

#### Fabric Community Update - August 2024

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

Top Solution Authors
Top Kudoed Authors