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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
bmacman
Frequent Visitor

Subtracting a column value on one date from the previous data date for a specific device

HI

I Have a problem I am trying to figure out. 

I am fairly new to Power BI.

I want to add a column that  takes the value of the SMU for a machine name and calculates the difference between it and the last value recieved.

So in the end a column that adds a value for SMU that would be just 1 days worth

 

bmacman_0-1670915803005.png

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@bmacman , a new column

new column =

var _max = maxx(filter(Table, [Machine name] = earlier([Machine name]) && [ShiftDateTime] < earlier([ShiftDateTime] ) ),[ShiftDateTime] )

return

[SMU] - maxx(filter(Table, [Machine name] = earlier([Machine name]) && [ShiftDateTime] =_max ),[SMU] ) 

 

 

Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
sgintowt
Helper I
Helper I

This works great. but how can I calculate the difference between dates in the above example.
The first date should show 0

v-yueyunzh-msft
Community Support
Community Support

Hi , @bmacman 

According to your description, you want to calculate the "Subtracting a column value on one date from the previous data date for a specific device". Right?

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1670988739193.png

(2)We can click "New Column" and enter:

Column = var _machine = [MACHINENAME] 
var _date = [Date] 
var _previous_date =MAXX( FILTER('Table', 'Table'[Date]<_date && 'Table'[MACHINENAME]=_machine) ,[Date])
var _pre_sum  =  SUMX( FILTER('Table','Table'[Date] = _previous_date) , [SUM])
return
[SUM]-_pre_sum

(3)Then we can get the data like this:

vyueyunzhmsft_1-1670988933161.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

 

 

amitchandak
Super User
Super User

@bmacman , a new column

new column =

var _max = maxx(filter(Table, [Machine name] = earlier([Machine name]) && [ShiftDateTime] < earlier([ShiftDateTime] ) ),[ShiftDateTime] )

return

[SMU] - maxx(filter(Table, [Machine name] = earlier([Machine name]) && [ShiftDateTime] =_max ),[SMU] ) 

 

 

Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks that worked. Much aprreciated.

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!

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