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!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
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?
@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]
)
)
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
User | Count |
---|---|
12 | |
11 | |
10 | |
9 | |
8 |