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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
ar13
Frequent Visitor

Calculate difference of 2 values with different tags, all within the same table and same date

Hi,

 

So I have data that looks like this: 

ar13_2-1605741107990.png

 

To sumarrize the data: so I have daily business days, in which I have data for each location and within each location, I can have up to 3 type of rates. What I am trying to accomplish is reproduce the following (done in Excel) to Power BI: 

ar13_1-1605741057540.png

It's basically to calculate the difference between each combination of location and type at a particular date. For example, I would want to know the difference between NY-A & CA-A for December 31st, 2019. I would then also like to graph the historical difference between NY-A & CA-A over a selected time period.

 

The examples I found online revolved around calculating the difference between data of the same category but with different dates (some of examples: https://stackoverflow.com/questions/57710425/find-difference-between-two-rows-by-usind-dax-in-power-... https://community.powerbi.com/t5/Desktop/Calculate-difference-between-two-rows-by-using-Index-column...).  I wanted to know if there was a way to do without having to duplicate the table in the query.

 

Thanks

 

 

1 ACCEPTED SOLUTION

Hi  @ar13 ,

 

You need to create another 4 columns as below:

Column-Location = LEFT('column table'[Location_type],2)
Column-Type = RIGHT('column table'[Location_type],1)
Row-Location = LEFT('Row table'[Location_type],2)
Row-Type = RIGHT('Row table'[Location_type],1)

And you will see:

v-kelly-msft_0-1606812066615.png

For the related .pbix file,pls see attahched.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

3 REPLIES 3
v-kelly-msft
Community Support
Community Support

Hi @ar13 ,

 

First create 2 dimensional tables as below:

column table = VALUES('Table'[Location_type])
Row table = VALUES('Table'[Location_type])

Then create a measure as below:

Measure = 
VAR _row=CALCULATE(MAX('Table'[rate]),FILTER(ALL('Table'),'Table'[Location_type]=MAX('Row table'[Location_type])&&'Table'[date]=MAX('Table'[date])))
var _column=CALCULATE(MAX('Table'[rate]),FILTER(ALL('Table'),'Table'[Location_type]=MAX('column table'[Location_type])&&'Table'[date]=MAX('Table'[date])))
Return
_row-_column

And you will see:

Screenshot 2020-11-23 151143.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Hi Kelly,

 

Thank you for taking the time to answer. I tried playing with your file and was wondering how to make slicers work in this context. For example, let's say we have the following slicers:

ar13_0-1606451133082.png

How can I make the slicers work in the data that I have. For example, if I only want to see Type A in the table, it doesn't currently filter out only the A. Also, how would everything work in a dataset that contains multiple dates of data, and a date slicer where only one date at a time is selected.

 

Thank you!

Hi  @ar13 ,

 

You need to create another 4 columns as below:

Column-Location = LEFT('column table'[Location_type],2)
Column-Type = RIGHT('column table'[Location_type],1)
Row-Location = LEFT('Row table'[Location_type],2)
Row-Type = RIGHT('Row table'[Location_type],1)

And you will see:

v-kelly-msft_0-1606812066615.png

For the related .pbix file,pls see attahched.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Helpful resources

Announcements
Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors