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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

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

Thanks that worked. Much aprreciated.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.