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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
newtralise
Frequent Visitor

How to subtract times based on criteria of another column

With the 'Time' category sorted from earliest to latest in my Table visualisation, I would like to find a way to subtract the corresponding times between the first Event Type ID = 13 and the last Event Type ID = 14. I would like to do this for both the Am and the Pm session. The times highlighted in yellow refer to the AM's session first 13 and last 14. The times corresponding to the blue circles refer to the PM's session first 13 and last 14. 

 

newtralise_0-1652407362854.png

 

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @newtralise ,

 

Please try this expression to do that:

Measure =
VAR _a =
    FILTER ( ALL ( 'Table (2)' ), [Time] < TIME ( 12, 0, 0 ) )
VAR _p =
    FILTER ( ALL ( 'Table (2)' ), [Time] >= TIME ( 12, 0, 0 ) )
RETURN
    IF (
        MAX ( 'Table (2)'[Time] ) < TIME ( 12, 0, 0 ),
        CALCULATE ( MAX ( 'Table (2)'[Time] ) - MIN ( 'Table (2)'[Time] ), _a ),
        CALCULATE ( MAX ( 'Table (2)'[Time] ) - MIN ( 'Table (2)'[Time] ), _p )
    )

 Result:

vchenwuzmsft_0-1652779225692.png

 

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

2 REPLIES 2
v-chenwuz-msft
Community Support
Community Support

Hi @newtralise ,

 

Please try this expression to do that:

Measure =
VAR _a =
    FILTER ( ALL ( 'Table (2)' ), [Time] < TIME ( 12, 0, 0 ) )
VAR _p =
    FILTER ( ALL ( 'Table (2)' ), [Time] >= TIME ( 12, 0, 0 ) )
RETURN
    IF (
        MAX ( 'Table (2)'[Time] ) < TIME ( 12, 0, 0 ),
        CALCULATE ( MAX ( 'Table (2)'[Time] ) - MIN ( 'Table (2)'[Time] ), _a ),
        CALCULATE ( MAX ( 'Table (2)'[Time] ) - MIN ( 'Table (2)'[Time] ), _p )
    )

 Result:

vchenwuzmsft_0-1652779225692.png

 

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to assist you. Avoid posting screenshots of your source data if possible.

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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