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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
crl_91
Frequent Visitor

Count number of times something happens in measure

I would like to count the number of times per date per part that the percentage #good/#done is below 85%, and do this in a measure.

E.g. - 1 jan 2024 for part X: (55+55)/(60+70) = 84,6%
       - 2 jan 2024 for part X: (55+55)/(55+75) = 84,6%

       - 3 jan 2024 for part X: (55+55)/(60+60) = 91,7%

 

crl_91_0-1710944037918.png

 

Eventually I would like to count the number of times per month that this happens, and also be able to show exactly on which day this happened. For example:

MonthNumber
Jan 20242
Feb 20245
March 20243

 

And if I then want to show it per day for january for example (and then only show these two rows):

DayNumber 
1 jan 20241
2 jan 20241

 

Hope anybody can help me :).

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @crl_91 ,

I create a table as you mentioned.

vyilongmsft_0-1711522712772.png

Then I create a measure named Percentage. Here is the DAX code.

Percentage =
VAR _currentDate =
    MAX ( 'Table'[Date] )
VAR _currentPart =
    MAX ( 'Table'[Part] )
VAR _SumGood =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Date] = _currentDate
                && 'Table'[Part] = _currentPart
        ),
        'Table'[#good]
    )
VAR _SumDone =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Date] = _currentDate
                && 'Table'[Part] = _currentPart
        ),
        'Table'[#done]
    )
RETURN
    _SumGood / _SumDone

vyilongmsft_1-1711522807672.png

I create a measure to satisfy your requirements.

MEASURE =
VAR _VirtualTbale =
    SUMMARIZE (
        'Table',
        'Table'[Date],
        'Table'[Part],
        "_percentage", 'Table'[Percentage]
    )
RETURN
    COUNTX ( FILTER ( _VirtualTbale, 'Table'[Percentage] < 0.85 ), [_percentage] )

vyilongmsft_2-1711523281644.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

 

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @crl_91 ,

I create a table as you mentioned.

vyilongmsft_0-1711522712772.png

Then I create a measure named Percentage. Here is the DAX code.

Percentage =
VAR _currentDate =
    MAX ( 'Table'[Date] )
VAR _currentPart =
    MAX ( 'Table'[Part] )
VAR _SumGood =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Date] = _currentDate
                && 'Table'[Part] = _currentPart
        ),
        'Table'[#good]
    )
VAR _SumDone =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Date] = _currentDate
                && 'Table'[Part] = _currentPart
        ),
        'Table'[#done]
    )
RETURN
    _SumGood / _SumDone

vyilongmsft_1-1711522807672.png

I create a measure to satisfy your requirements.

MEASURE =
VAR _VirtualTbale =
    SUMMARIZE (
        'Table',
        'Table'[Date],
        'Table'[Part],
        "_percentage", 'Table'[Percentage]
    )
RETURN
    COUNTX ( FILTER ( _VirtualTbale, 'Table'[Percentage] < 0.85 ), [_percentage] )

vyilongmsft_2-1711523281644.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

 

 

 

Hi Yilong,

 

Thank you so much for your help! However, I needed to add more information to the measure, and now I am stuck again. Could you maybe help me with this one: Count number of times something happens in measure - Microsoft Fabric Community

It works perfectly :). Thank you for your help!

Greg_Deckler
Super User
Super User

@crl_91 Maybe:

Measure = 
  VAR __Table = 
    ADDCOLUMNS(
      SUMMARIZE('Table', [Date], [Part], "__good", SUM('Table'[# good]), "__done", SUM('Table'[# done]),
      "__PercentGood", DIVIDE( __good, __done, 0 )
    )
  VAR __Result = COUNTROWS( FILTER( __Table, [__PercentGood] < .85 )
RETURN
  __Result


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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