Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Matt_Alexander
Advocate III
Advocate III

DAX to countrow if sum condition is met

Hi, 

 

Trying to work out the DAX measure to count the rows if the sum of the amount is greater than 0 per ClientID, but to no avail. 

 

Data is as follows:

ClientIDAmount
10
110
20
3100

 

Each row is a meeting, and I need to count the number of meetings in the case that the sum of the amount per Client ID is >0. 

 

So, figure for above table would be 3 meetings.

 

What would be the best way to achieve this?

 

Many thanks!

 

Matt

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

You could do a SUMMARIZE by Client ID and then do a simple CALCULATE, COUNT, FILTER [Amount] > 0


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

You could do a SUMMARIZE by Client ID and then do a simple CALCULATE, COUNT, FILTER [Amount] > 0


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Thanks for the pointer @Greg_Deckler

 

I've created a table with summarize and then counted the rows in the original table, filtering by those clientID with amounts >0. 

 

Table = SUMMARIZE(Sheet1;Sheet1[ClientID];"Test";sum(Sheet1[Amount]))

 

Measure 4 = CALCULATE(COUNTROWS(Sheet1); filter('Table';'Table'[Test]>0))

 

I presume using an intermediary table will impact on the size of the data model? Is that the best way of doing it or can I do it all in one measure without the need for the additional table?

 

Thanks for your time and assistance.

 

Matt

 

 

You should be able to do that in a single measure, something like:

 

Measure 4 = 

VAR mytable = SUMMARIZE(Sheet1;Sheet1[ClientID];"Test";sum(Sheet1[Amount]))
 
RETURN CALCULATE(COUNTROWS(mytable); filter('mytable';[Test]>0))

@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Perfect, thanks. That worked when I based the count on the original table (Sheet1) in the return calculate. 

 

 

Final Measure = 
   var SummaryTable = SUMMARIZE(Sheet1;Sheet1[ClientID]; "Test"; sum(Sheet1[Amount]))

RETURN

  CALCULATE(COUNTROWS(Sheet1); filter(SummaryTable; [Test] > 0))

 

 

Once again thanks for your help.

 

Matt

Ah, that makes sense, glad you got it worked out!


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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