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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
nishanthapbi
Regular Visitor

DAX calculation

DAX.pngI 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) 

2 ACCEPTED SOLUTIONS
Phil_Seamark
Microsoft Employee
Microsoft Employee

HI @nishanthapbi

 

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


image.png

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

Hi @nishanthapbi

 

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

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

5 REPLIES 5
Phil_Seamark
Microsoft Employee
Microsoft Employee

HI @nishanthapbi

 

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


image.png

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thank you very much for the help, if need to multiply the time gap with the previous flow rate how it's posible ??

 

Hi @nishanthapbi

 

Do you mean 2 back?  The calc I posted looks back 1 time period


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Time gap calculation is correct, I mean that time gap need to multiply with the previous flow rate to take the consumption.

 

 

DAX.pngEg: consumption (kg) = flow (Kg/min) (Green Color) / 60 * Time (Yellow - Red)

 

Hi @nishanthapbi

 

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

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

Top Solution Authors
Top Kudoed Authors