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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Matthew999
New Member

Difference between price of two products for same date

So I was wondering how I would calculate the difference in DAX between two products in my table for the same date so I can see how the price spread changes over time. So my table would look like this: 

DateProductPrice
7/18/2019Corn100
7/18/2019Sugar50
7/17/2019Corn90
7/17/2019Sugar60

And I would like this kind of output: 

 Corn minus Sugar
7/18/201950
7/17/201930

 

Ideally I would also be changing the dates (so maybe only charting the spread evolution over last 6 months) so FILTER incorporation would be ideal. Thanks in advance for any insight on how I could do this!

1 ACCEPTED SOLUTION
Omega
Impactful Individual
Impactful Individual

Assuming you only have two products, try the below measure: 

 

Measure = CALCULATE(SUM('Table'[Price]),'Table'[Product]="Corn") - CALCULATE(SUM('Table'[Price]),'Table'[Product]="Sugar")

View solution in original post

2 REPLIES 2
Omega
Impactful Individual
Impactful Individual

Assuming you only have two products, try the below measure: 

 

Measure = CALCULATE(SUM('Table'[Price]),'Table'[Product]="Corn") - CALCULATE(SUM('Table'[Price]),'Table'[Product]="Sugar")

That works! While there are more than one product, I can just make different measures because each product actually has a lot of other attributes attached (the same product will actually have multiple attributes that I will need to differentiate by like vendor source). Now that I have the framework I will give it a shot. Thanks!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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