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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
jsanchezm
Frequent Visitor

Create a measure comparing two values of different rows and columns if they meet two conditions

Hi,

 

I'm stuck trying to create a measure that compares values from two columns of two different rows, but from the same table, if, and only if, they meet two conditions:

In example: if the two rows are from the same date (data in my language) and it is also from the same bus, compare the H_FIN from the first one to the H_INI of the second one. For the data included in the next image, the first row wouldn't be compared to any other row, as it meets the date condition, but not the bus one (it is the only one with the bus 12377). The second row wouldn't need to be compared, as it has not any previous row of that meets the two condition criteria, but the third one as it is from the same date and bus of the previous one, would need to calculate and get the value "01:55" as it is the duration between the H_FIN of the first row and H_INI of the second one.

 

jsanchezm_0-1649843877895.png

 

I've seen some posts talking about similar things, but they don't seem to fit with my problem or, at least, I can't see how to work the examples for my problem.

 

Any hints, please? Thanks in advance for your help.

 

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

Hi @jsanchezm ,

According to your description, here's my solution.

Create a measure.

 

Diff =
VAR _Pre =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[DATE] = MAX ( 'Table'[DATE] )
                && 'Table'[BUS] = MAX ( 'Table'[BUS] )
                && 'Table'[IDTRAM] < MAX ( 'Table'[IDTRAM] )
        ),
        'Table'[H_FIN]
    )
RETURN
    IF ( _Pre = BLANK (), BLANK (), MAX ( 'Table'[H_INI] ) - _Pre )

 

Get the correct result.

vkalyjmsft_0-1650249295676.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

1 REPLY 1
v-yanjiang-msft
Community Support
Community Support

Hi @jsanchezm ,

According to your description, here's my solution.

Create a measure.

 

Diff =
VAR _Pre =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[DATE] = MAX ( 'Table'[DATE] )
                && 'Table'[BUS] = MAX ( 'Table'[BUS] )
                && 'Table'[IDTRAM] < MAX ( 'Table'[IDTRAM] )
        ),
        'Table'[H_FIN]
    )
RETURN
    IF ( _Pre = BLANK (), BLANK (), MAX ( 'Table'[H_INI] ) - _Pre )

 

Get the correct result.

vkalyjmsft_0-1650249295676.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.