Skip to main content
cancel
Showing results for 
Search instead 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

Reply
Anonymous
Not applicable

Wrong total sum, distinct count

I have this table:

grafik.png

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.

grafik.png

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

Is there a DAX formula to do so?

2 ACCEPTED SOLUTIONS

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.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

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.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

12 REPLIES 12
Greg_Deckler
Super User
Super User

Can you post that raw data as text and can you also post your expected result of your sample data?

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

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

2.png

Should be the result

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.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

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

 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
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.

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.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

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?

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.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

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?

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors