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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
JacobCoops
Frequent Visitor

Count If measure

Hello

 

I am trying to create a measure that returns the percentage of customers with 3 or more logins. My dataset is a list of CustomerIDs and timestamps (logins) where one row equals one login. If i were to do this in Excel i would use the CountIf function on a pivoted dataset (to group the customer IDs):

 

Excel.jpg

 

 

 

 

 

 

 

 

 

 

My dataset look like this:

PBI Data.jpg

 

 

 

 

 

 

 

 

 

I have tried creating a calcuated coloumn that correctly counts the total number of logins pr. CustomerID (KundeID in the picture). The issue is, however, that the calculated coloumn does not respond to the date-slicers in the report. The users therefore cant choose to only evaluate 2020 data, for instance, which is why i figured it had to be a measure.

Based on the picture above the measure would return the number 2 since Customer ID 96090 is represented 5 times and ID 96045 is represented  4 times and the remaining two is shown 1 time each.

 

My current attempts have led me to this: 

PBI Example.jpg 

 

 

 

 

 

 

 

 

 

 

 

 

What i would want the measure to do is to summarize the coloumn "Countrows 3".

 

As a bonus question i would like to know, if it is possible to change the threshold "3" to a dynamic value that users can change in a slicer?

 

I am a complete novice at PBI and DAX so there might be something obvious that i am missing so i appreciate any pointers. 

Thank you for your time

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Measure = 

  VAR __Table = 

    FILTER(

      SUMMARIZE(

        'Table',

        [KundeID],

        "__Count", COUNTROWS('Table')

      ),

     [__Count] > 3

  )

RETURN

  COUNTROWS(__Table)


@ 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

3 REPLIES 3
Greg_Deckler
Super User
Super User

Measure = 

  VAR __Table = 

    FILTER(

      SUMMARIZE(

        'Table',

        [KundeID],

        "__Count", COUNTROWS('Table')

      ),

     [__Count] > 3

  )

RETURN

  COUNTROWS(__Table)


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

Hi Greg

 

This is friggin amazing. Thank you very much!

Cool, glad it worked for you! 🙂

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

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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