Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
I need to create calculated column to get the consumption (kg) using a formula in PBI. Here I have the flow rate (Kg/min) and need to get the time from subtracting the previous time which is in the same Item and same day (because time gap of the two consecutive data is different). With this calculation fist raw of the Item will get 0 as the time is become 0 and others will get the respective amount corresponding to the time.
**Consumption (Kg) = Flow (Kg/min)/60 * time (seconds)
Solved! Go to Solution.
This calculated column gets pretty close. It shouldn't require too much tweaking.
Consumption (Kg) =
VAR Yellow = 'Table1'[Time]
VAR Red = MAXX(
FILTER(
'Table1',
'Table1'[Date] = EARLIER('Table1'[Date]) &&
'Table1'[Item] = EARLIER('Table1'[Item]) &&
'Table1'[Time] < EARLIER('Table1'[Time])
),'Table1'[Time])
VAR TimeGap = DATEDIFF(Red,Yellow,SECOND)
VAR Flow = 'Table1'[Flow (Kg/min)]
RETURN
(Flow/60) * TimeGap
I've tweaked the calculation and highlighted the changes in bold.
Consumption (Kg) =
VAR Yellow = 'Table1'[Time]
VAR Red = MAXX(
FILTER(
'Table1',
'Table1'[Date] = EARLIER('Table1'[Date]) &&
'Table1'[Item] = EARLIER('Table1'[Item]) &&
'Table1'[Time] < EARLIER('Table1'[Time])
),'Table1'[Time])
VAR TimeGap = DATEDIFF(Red,Yellow,SECOND)
VAR Flow = 'Table1'[Flow (Kg/min)]
VAR PreviousFlow = MAXX(FIlTER('Table1',Table1[Item] = EARLIER('Table1'[Item]) && 'Table1'[Date] = EARLIER('Table1'[Date]) && 'Table1'[Time] = Red),'Table1'[Flow (Kg/Min)])RETURN
(PreviousFlow/60) * TimeGap
This calculated column gets pretty close. It shouldn't require too much tweaking.
Consumption (Kg) =
VAR Yellow = 'Table1'[Time]
VAR Red = MAXX(
FILTER(
'Table1',
'Table1'[Date] = EARLIER('Table1'[Date]) &&
'Table1'[Item] = EARLIER('Table1'[Item]) &&
'Table1'[Time] < EARLIER('Table1'[Time])
),'Table1'[Time])
VAR TimeGap = DATEDIFF(Red,Yellow,SECOND)
VAR Flow = 'Table1'[Flow (Kg/min)]
RETURN
(Flow/60) * TimeGap
Thank you very much for the help, if need to multiply the time gap with the previous flow rate how it's posible ??
Do you mean 2 back? The calc I posted looks back 1 time period
Time gap calculation is correct, I mean that time gap need to multiply with the previous flow rate to take the consumption.
Eg: consumption (kg) = flow (Kg/min) (Green Color) / 60 * Time (Yellow - Red)
I've tweaked the calculation and highlighted the changes in bold.
Consumption (Kg) =
VAR Yellow = 'Table1'[Time]
VAR Red = MAXX(
FILTER(
'Table1',
'Table1'[Date] = EARLIER('Table1'[Date]) &&
'Table1'[Item] = EARLIER('Table1'[Item]) &&
'Table1'[Time] < EARLIER('Table1'[Time])
),'Table1'[Time])
VAR TimeGap = DATEDIFF(Red,Yellow,SECOND)
VAR Flow = 'Table1'[Flow (Kg/min)]
VAR PreviousFlow = MAXX(FIlTER('Table1',Table1[Item] = EARLIER('Table1'[Item]) && 'Table1'[Date] = EARLIER('Table1'[Date]) && 'Table1'[Time] = Red),'Table1'[Flow (Kg/Min)])RETURN
(PreviousFlow/60) * TimeGap
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.
| User | Count |
|---|---|
| 26 | |
| 23 | |
| 19 | |
| 18 | |
| 15 |
| User | Count |
|---|---|
| 47 | |
| 44 | |
| 43 | |
| 35 | |
| 31 |