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
Qotsa
Helper V
Helper V

How to perform calculations on this measure

Hi,

 

I have this measure: 

Rest Period Decimal Hrs =
VAR thisdate =
MIN ( 'powerbi114 view_finance'[Date] )
VAR thisfirst =
MIN ( [Time of First Call] )
VAR prevdate =
CALCULATE (
MAX ( 'powerbi114 view_finance'[Date] ),
ALL ( 'powerbi114 view_finance' ),
VALUES ( 'powerbi114 view_finance'[carer_id] ),
'powerbi114 view_finance'[Date] < thisdate
)
VAR prevlast =
CALCULATE (
MAX ( 'powerbi114 view_finance'[Time of Last Call] ),
ALL ( 'powerbi114 view_finance' ),
VALUES ( 'powerbi114 view_finance'[carer_id] ),
'powerbi114 view_finance'[Date] = prevdate
)
RETURN
IF (
NOT ( ISBLANK ( prevdate ) ),
24
* FIXED ( ( thisdate + thisfirst ) - ( prevdate + prevlast ), 3 )
)
 
It returns the time between the Latest Finish Time from the previous date and the Earliest Start Time of the next date for each carer_id.
 
Qotsa_1-1656490890862.png

 


 

The issue I am having is how to perform calculations on the measure.

For example, I want a sum of all values < 11 but sumx does not work with boolean values.

 

Less than 11 = SUMX('powerbi114 view_finance',[Daily Rest Decimal Hrs] < 11)
 
Qotsa_2-1656493946868.png

 

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@Qotsa try:

 

Less than 11 = 
SUMX(
    FILTER(
        SUMMARIZE(        
            'powerbi114 view_finance',
            'powerbi114 view_finance'[carer_id],
            'powerbi114 view_finance'[Date]
       )
        [Daily Rest Decimal Hrs] < 11
    )
    ,1
)

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

View solution in original post

13 REPLIES 13
Qotsa
Helper V
Helper V

Thks again. Can you explain what is happening here?

SUMX(
    FILTER(
        SUMMARIZE(        
            'powerbi114 view_finance',
            'powerbi114 view_finance'[carer_id],
            'powerbi114 view_finance'[Date]
       )
SpartaBI
Community Champion
Community Champion

SUMMARIZE(        
            'powerbi114 view_finance',
            'powerbi114 view_finance'[carer_id],
            'powerbi114 view_finance'[Date]
       )

This is the distinct combination of these 2 columns.
Check out:
https://dax.guide/summarizea


 

Ok. Thanks very much.

SpartaBI
Community Champion
Community Champion

@Qotsa my pleasure 🙂
Don't forget to check out my showcase report - really, got some high level stuff there. Sure you will find there a lot of cool ideas. 
https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543
Give it a thumbs up over there if you liked it 🙂

SpartaBI
Community Champion
Community Champion

@Qotsa I think you are trying to do:
Less than 11 = SUMX(FILTER('powerbi114 view_finance',[Daily Rest Decimal Hrs] < 11),[Daily Rest Decimal Hrs])
 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

@SpartaBI Thks. I'm not getting desired results. Should return a sum of 2.

Qotsa_0-1656498231428.png

 

SpartaBI
Community Champion
Community Champion

@Qotsa oh, so do this:) :
Less than 11 = SUMX(FILTER('powerbi114 view_finance',[Daily Rest Decimal Hrs] < 11),1)


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

It's getting closer.

Qotsa_0-1656502631818.png

 

SpartaBI
Community Champion
Community Champion

@Qotsa try:

 

Less than 11 = 
SUMX(
    FILTER(
        SUMMARIZE(        
            'powerbi114 view_finance',
            'powerbi114 view_finance'[carer_id],
            'powerbi114 view_finance'[Date]
       )
        [Daily Rest Decimal Hrs] < 11
    )
    ,1
)

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

That's fantastic. I'm getting the correct results for <11.

When I change it tho to =, it doesn't return the desired result. Any idea why?

 

Qotsa_0-1656508503529.png

 

SpartaBI
Community Champion
Community Champion

@Qotsa I guess it's not exactly 32.26 🙂
Try to verify by doing 

 

Less than 11 = 
SUMX(
    FILTER(
        SUMMARIZE(        
            'powerbi114 view_finance',
            'powerbi114 view_finance'[carer_id],
            'powerbi114 view_finance'[Date]
       )
        [Daily Rest Decimal Hrs] > 32 && [Daily Rest Decimal Hrs] < 33 
    )
    ,1
)

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Yep, that gives correct result.

Qotsa_0-1656510031442.png

 

SpartaBI
Community Champion
Community Champion

@Qotsa my pleasure 🙂
Please don't forget to accept the previous message as a solution for community visibility.
P.S. Check out my showcase report - got some high level stuff there. Sure you will find there a lot of cool ideas. 
https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543
Give it a thumbs up over there if you liked it 🙂

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.

Top Solution Authors