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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
WTAS80486
Helper IV
Helper IV

how to compare two rows in column and return value in DAX calculated column

Ankita80486_0-1661956767123.png

I am using this to calculate cumulative runhours

 

Rolling Runhours = CALCULATE (
                SUM ( 'MeterReading'[ Run Hours]),
                FILTER (
                    ALL ( 'MeterReading'),
                    'MeterReading'[Asset PK ID] = EARLIER ( 'MeterReading'[Asset PK ID]  )
                        && 'MeterReading'[readingdate]<= EARLIER ('MeterReading'[readingdate])
                )
            )
 
But this returns
 
Ankita80486_1-1661956892462.png

same value for same dates. I want to have 0 in first row for 11/9 and 265 in second row for 11/9

 

How can i achieve that?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @WTAS80486 ,

I have create a simple sample, please refer to it to see if it helps you.

Add an index column first.

Then create a measure.

Measure =
VAR _count =
    CALCULATE (
        COUNT ( MeterReading[readingdate] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] = SELECTEDVALUE ( MeterReading[readingdate] )
        )
    )
VAR _1mindate =
    CALCULATE (
        MIN ( MeterReading[Index] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] = SELECTEDVALUE ( MeterReading[readingdate] )
        )
    )
VAR _result =
    CALCULATE (
        SUM ( MeterReading[Run Hours] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] <= SELECTEDVALUE ( MeterReading[readingdate] )
        )
    )
RETURN
    IF ( _count <> 1 && _1mindate = MAX ( MeterReading[Index] ), 0, _result )

 

or a column.

Column =
VAR _count =
    CALCULATE (
        COUNT ( MeterReading[readingdate] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] = EARLIER ( MeterReading[readingdate] )
        )
    )
VAR _1mindate =
    CALCULATE (
        MIN ( MeterReading[Index] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] = EARLIER ( MeterReading[readingdate] )
        )
    )
VAR _result =
    CALCULATE (
        SUM ( MeterReading[Run Hours] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] <= EARLIER ( MeterReading[readingdate] )
        )
    )
RETURN
    IF ( _count <> 1 && _1mindate = ( MeterReading[Index] ), 0, _result )

vpollymsft_0-1662348014683.png

If I have misunderstood your meaning, please provide a pbix file without privacy information and more details with your desired output.

 

Best Regards

Community Support Team _ Polly

 

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

3 REPLIES 3
Anonymous
Not applicable

Hi @WTAS80486 ,

I have create a simple sample, please refer to it to see if it helps you.

Add an index column first.

Then create a measure.

Measure =
VAR _count =
    CALCULATE (
        COUNT ( MeterReading[readingdate] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] = SELECTEDVALUE ( MeterReading[readingdate] )
        )
    )
VAR _1mindate =
    CALCULATE (
        MIN ( MeterReading[Index] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] = SELECTEDVALUE ( MeterReading[readingdate] )
        )
    )
VAR _result =
    CALCULATE (
        SUM ( MeterReading[Run Hours] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] <= SELECTEDVALUE ( MeterReading[readingdate] )
        )
    )
RETURN
    IF ( _count <> 1 && _1mindate = MAX ( MeterReading[Index] ), 0, _result )

 

or a column.

Column =
VAR _count =
    CALCULATE (
        COUNT ( MeterReading[readingdate] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] = EARLIER ( MeterReading[readingdate] )
        )
    )
VAR _1mindate =
    CALCULATE (
        MIN ( MeterReading[Index] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] = EARLIER ( MeterReading[readingdate] )
        )
    )
VAR _result =
    CALCULATE (
        SUM ( MeterReading[Run Hours] ),
        FILTER (
            ALL ( MeterReading ),
            MeterReading[readingdate] <= EARLIER ( MeterReading[readingdate] )
        )
    )
RETURN
    IF ( _count <> 1 && _1mindate = ( MeterReading[Index] ), 0, _result )

vpollymsft_0-1662348014683.png

If I have misunderstood your meaning, please provide a pbix file without privacy information and more details with your desired output.

 

Best Regards

Community Support Team _ Polly

 

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

@Anonymous Thanks

Kriekis
Frequent Visitor

1. You can add Index column

Kriekis_0-1661971032528.png

2. Then You add readingdate_v2

Kriekis_1-1661971106344.png

3. And finally Your [Rolling Runhours] think works fine

Kriekis_2-1661971196094.png

 

This solution works fine if You don't get exactly the same runhours in the same day multiple times.

If this is a case then adding additional Index column in Power Query can help here.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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