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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pbiuser12345
Helper I
Helper I

Measure Behaviour in Matrix Visual

Hello,

 

I am creating a measure (expression at the very bottom of the post) to tell me the percentage of items that completed on time.  To that end, I have a calculated column that is basically [# yes] / ([# yes] + [# no].  However when I put this intro a matrix visual to validate the answer, this is what I ended up with:

 

image.png

This confuses me because I thought that the measure would be calculated independently for each row, so I would end up with 100% on the 'Yes' row, and 0% on the 'No' and 'N/A' rows.

 

I am a relative newbie to Power BI and DAX, so I assume I'm just missing something here.  Why does this not behave the way I think it should?  What changes would need to be made to make it work that way?

 

Thanks for your help!

% Programs Completed On Time =
    CALCULATE(
        DISTINCTCOUNT('Table - PROGRAMS'[ID]),
        && 'Table - PROGRAMS'[PROGRAM_STATUS] = "Completed"
        && 'Table - PROGRAMS'[PROGRAM_COMPLETED_ON_TIME] = "Yes"
    )
    /
    CALCULATE(
        DISTINCTCOUNT('Table - PROGRAMS'[ID]),
        && 'Table - PROGRAMS'[PROGRAM_STATUS] = "Completed"
        && 'Table - PROGRAMS'[PROGRAM_COMPLETED_ON_TIME] IN {"Yes", "No"}
    )

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@pbiuser12345 It's because you are trying to use CALCULATE with a single table. That tends not to work. Ditch CALCULATE can go with COUNTROWS( DISTINCT( SELECTCOLUMNS( FILTER(...), ... ) ) )


@ 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

@pbiuser12345 It's because you are trying to use CALCULATE with a single table. That tends not to work. Ditch CALCULATE can go with COUNTROWS( DISTINCT( SELECTCOLUMNS( FILTER(...), ... ) ) )


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

Thanks Greg, that put me on the right track.  The below expression is working the way I would have expected.

 

I'm not sure I understand the 'why' of this though.  Are you able to elaborate or point me to something that explains why CALCULATE is bad on a single table?  Should I consider it best practice to reserve CALCULATE for measures that span multiple tables, and stick to more basic/fundamental functions for single table applications?

 

% Programs Completed On Time = 
    COUNTROWS(
        FILTER(
            'Table - PROGRAMS',
            && 'Table - PROGRAMS'[PROGRAM_STATUS] = "Completed"
            && 'Table - PROGRAMS'[PROGRAM_COMPLETED_ON_TIME] = "Yes"
        )
    )
    /
    COUNTROWS(
        FILTER(
            'Table - PROGRAMS',
            && 'Table - PROGRAMS'[PROGRAM_STATUS] = "Completed"
            && 'Table - PROGRAMS'[PROGRAM_COMPLETED_ON_TIME] IN {"Yes", "No"}
        )
    )

 

Have a read of this, which I think answers the "why". https://www.sqlbi.com/articles/the-importance-of-star-schemas-in-power-bi/ 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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