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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
oldandnew
Frequent Visitor

Find the Volume Change for the Same Material at Each Plant in Chronological Order

The dataset shows facility, material number, volume, volume change date, and the ranking (sorts the dates from earliest volume change date as 1 to the most recent). I would like to calculate the volume change between 2 dates for each material at each plant. See the table below of what I have and what I would like to achieve in Power BI.

 

 

What I have: 

Facility Material Number        Volume                 Volume Change Date            Ranking
6879    333555                        10,000.37              6/8/2006                               1
6879    333555                        125,433.00            1/28/2009                             2
6879    333555                        110,000.00           11/26/2019                            3
6879    258852                            3,052.00             5/12/2008                            1
6879    258852                            1,003.00             8/18/2016                            2
3423    435303                          21,000.00             3/23/2018                            1
3423    435303                          21,000.00             6/24/2019                            2
3423    209890                                        -            10/4/2015                             1
3423    209890                                        -             7/29/2020                            2

 

 

 

What I would like to achieve:

Facility Material Number        Volume                 Volume Change Date            Ranking       Volume Change 
6879    333555                        10,000.37              6/8/2006                               1                         0
6879    333555                        125,433.00            1/28/2009                             2                   115,432.63
6879    333555                        110,000.00           11/26/2019                            3                    (15,433.00)
6879    258852                            3,052.00             5/12/2008                            1                         0
6879    258852                            1,003.00             8/18/2016                            2                     (2,049.00)
3423    435303                          21,000.00             3/23/2018                            1                         0
3423    435303                          21,000.00             6/24/2019                            2                         0
3423    209890                                        -            10/4/2015                             1                         0
3423    209890                                        -             7/29/2020                            2                         0

 

I am still new to Power BI and DAX. Been boggling my mind on how to do this. Any help would be appreciated. 

1 ACCEPTED SOLUTION
v-jialongy-msft
Community Support
Community Support

Hi @oldandnew 

 

Based on your needs, I have created the following form

vjialongymsft_0-1706078410311.png

 

First you can create an index column in power query

vjialongymsft_1-1706078508966.png

 

 

Then you can use the following dax to achieve your goal

NewColumn = 
IF (
    'Table'[Ranking] = 1,
    0,
    'Table'[Volume] - LOOKUPVALUE('Table'[Volume], 'Table'[Index], 'Table'[Index] - 1)
)

 

This is the result

vjialongymsft_2-1706078747492.png

 

 

 

Best Regards,

Jayleny

 

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

View solution in original post

2 REPLIES 2
v-jialongy-msft
Community Support
Community Support

Hi @oldandnew 

 

Based on your needs, I have created the following form

vjialongymsft_0-1706078410311.png

 

First you can create an index column in power query

vjialongymsft_1-1706078508966.png

 

 

Then you can use the following dax to achieve your goal

NewColumn = 
IF (
    'Table'[Ranking] = 1,
    0,
    'Table'[Volume] - LOOKUPVALUE('Table'[Volume], 'Table'[Index], 'Table'[Index] - 1)
)

 

This is the result

vjialongymsft_2-1706078747492.png

 

 

 

Best Regards,

Jayleny

 

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

Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

Column = if(ISBLANK(LOOKUPVALUE(Data[Volume],Data[Volume Change date],CALCULATE(MAX(Data[Volume Change date]),FILTER(Data,Data[Facility]=EARLIER(Data[Facility])&&Data[Material Number]=EARLIER(Data[Material Number])&&Data[Volume Change date]<EARLIER(Data[Volume Change date]))),Data[Facility],Data[Facility],Data[Material Number],Data[Material Number])),0,Data[Volume]-LOOKUPVALUE(Data[Volume],Data[Volume Change date],CALCULATE(MAX(Data[Volume Change date]),FILTER(Data,Data[Facility]=EARLIER(Data[Facility])&&Data[Material Number]=EARLIER(Data[Material Number])&&Data[Volume Change date]<EARLIER(Data[Volume Change date]))),Data[Facility],Data[Facility],Data[Material Number],Data[Material Number]))

Hope this helps.

Ashish_Mathur_0-1705122093188.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.