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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
justlogmein
Helper III
Helper III

Reset cummulative total/running total when other column value is TRUE

What I want to do is pretty straightforward but all the examples I have tried have not worked so far and I'm stressing a little because I need to complete this today.

 

I have a table of engine oil samples for heavy mining machinery and a column called "Engine Oil Changed" which indicates if the engine oil was changed when that sample was taken. Now I simply want to find out how many hours the oil had before it was changed. I have a running total column for the hours which works fine. I just need to reset this running total when the "Engine Oil Changed" column is true, noting that I need to have it grouped by "Unit Number".

 

Is anyone able to provide some code to put into this column?

 

https://jmservicescomau-my.sharepoint.com/:u:/g/personal/jacob_jmservices_com_au/EaFFuIzsncpKiGoUSuw...

1 REPLY 1
tamerj1
Community Champion
Community Champion

@justlogmein 
Hope it's not too late 🙂

Here is the sample file with the solution https://www.dropbox.com/t/HZEL59KsSFlicaPV 
Please use the following code

Fluid Hours Reset when Oil Changed = 
IF ( 
    'Sample Data'[Oil Changed] = FALSE ( ),
    VAR CurrentDate = 'Sample Data'[Sample Date]
    VAR DatesBeforeTable1 = FILTER ( 'Sample Data', 'Sample Data'[Sample Date] <= CurrentDate )
    VAR DatesBeforeTable2 = FILTER ( 'Sample Data', 'Sample Data'[Sample Date] < CurrentDate )
    VAR PrevuiousChangesTable = FILTER ( DatesBeforeTable2, 'Sample Data'[Oil Changed] = TRUE ( ) )
    VAR PreviousChangeDate = MAXX ( PrevuiousChangesTable, 'Sample Data'[Sample Date] )
    VAR ResultTable = FILTER ( DatesBeforeTable1, 'Sample Data'[Sample Date] > PreviousChangeDate )
    RETURN
        SUMX (
            ResultTable,
            'Sample Data'[Hours Since Previous Reading]
        )
)

 If you want to include the last change hours with the sum use this code with a very tiny change

Fluid Hours Reset when Oil Changed = 
IF ( 
    'Sample Data'[Oil Changed] = FALSE ( ),
    VAR CurrentDate = 'Sample Data'[Sample Date]
    VAR DatesBeforeTable1 = FILTER ( 'Sample Data', 'Sample Data'[Sample Date] <= CurrentDate )
    VAR DatesBeforeTable2 = FILTER ( 'Sample Data', 'Sample Data'[Sample Date] < CurrentDate )
    VAR PrevuiousChangesTable = FILTER ( DatesBeforeTable2, 'Sample Data'[Oil Changed] = TRUE ( ) )
    VAR PreviousChangeDate = MAXX ( PrevuiousChangesTable, 'Sample Data'[Sample Date] )
    VAR ResultTable = FILTER ( DatesBeforeTable1, 'Sample Data'[Sample Date] >= PreviousChangeDate )
    RETURN
        SUMX (
            ResultTable,
            'Sample Data'[Hours Since Previous Reading]
        )
)

 

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

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

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.