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
Anonymous
Not applicable

Calculated Column based on row diff

Hello,

 

I have a custom dataset as shown below and I am looking for a calculated column called "Price change" which do the following operation,

 

For the same material, look for the valid_to date and if it is the first valid date then price change is 0 else diff of the price.

 


Material      valid_from        valid_to           price     Pricechange
16558          5/20/2018        10/20/2018      12           0
16558          10/21/2018     12/21/2018      10          -2
16558          12/22/2018      12/31/9999      14          4
16559          6/21/2018        10/22/2018      12         0
16559          10/23/2018      12/31/9999       10        -2

 

 

Thanks in advance.

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula work

=if(ISBLANK(LOOKUPVALUE(Data[Price],[Material],Data[Material],Data[Valid_from],CALCULATE(MAX(Data[Valid_from]),FILTER(Data,Data[Material]=EARLIER(Data[Material])&&Data[Valid_from]<EARLIER(Data[Valid_from]))))),0,[Price]-LOOKUPVALUE(Data[Price],[Material],Data[Material],Data[Valid_from],CALCULATE(MAX(Data[Valid_from]),FILTER(Data,Data[Material]=EARLIER(Data[Material])&&Data[Valid_from]<EARLIER(Data[Valid_from])))))

Hope this helps.

Untitled.png


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

View solution in original post

Anonymous
Not applicable

Thank you very much...It worked like a charm.

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula work

=if(ISBLANK(LOOKUPVALUE(Data[Price],[Material],Data[Material],Data[Valid_from],CALCULATE(MAX(Data[Valid_from]),FILTER(Data,Data[Material]=EARLIER(Data[Material])&&Data[Valid_from]<EARLIER(Data[Valid_from]))))),0,[Price]-LOOKUPVALUE(Data[Price],[Material],Data[Material],Data[Valid_from],CALCULATE(MAX(Data[Valid_from]),FILTER(Data,Data[Material]=EARLIER(Data[Material])&&Data[Valid_from]<EARLIER(Data[Valid_from])))))

Hope this helps.

Untitled.png


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

Thank you very much...It worked like a charm.

You are welcome.


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

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.