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
MrKrukauskas
Helper I
Helper I

Calculate difference between two filtered measures

Hi Power BI Community, hope you all staying safe!

My first question here, so please don't judge me 😄

I have been trying to calculate revenue difference, for the same Division, between two different dates (Data Load Date and Historical Date).

Here the the User steps:

  1. Selects Division
  2. Selects Data Load  Date --->> 1st measure shows the revenue for that division for that date
  3. Selects Historical Date --->> 2nd  measure shows the revenue for that division for that date
  4. 3rd measure calculates the difference between the 1st and the 2nd measure. 

I have tried to use the same Data Load Date to create all 3 measures.

I also tried to duplicate the table and just renamed the second table and Data Load Date to Historical Date.

 

Table A:

Division

Revenue

Target

Data Load Date

 

Table B (a copy):

Division

Revenue

Target

Historical Date (rename from Data Load Date)

 


MrKrukauskas_0-1593219215302.png
MrKrukauskas_1-1593219259548.png

How can I create a measure to calculate the difference between 1st and 2nd value?

Much appreciate the help!

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@MrKrukauskas 

I think what you will need is 2 date lists, one linked to each field [Data Load Date] and [Historical Date]
2020-06-26_18-59-06.png

You use the dates from those 2 tables in the slicers and write the measures so the [Data Load Amonut] ignores the filters from the 'Historical Dates' table and vice versa.

Total Amount = SUM ('Table'[Amount] )
Data Load Amonut = CALCULATE( [Total Amount],ALL('Historical Dates') )
Historical Amount = CALCULATE( [Total Amount],ALL('Data Load Dates') )
Difference = [Data Load Amonut] - [Historical Amount]

2020-06-26_19-01-54.png

On both of the date slicers I also added a filter where [Total Amount] is not blank so that only dates with an amount would show in the list.

I have attached my sample file for you to look at so you can see how I made the two date tables. 

View solution in original post

6 REPLIES 6
jdbuchanan71
Super User
Super User

@mase_53 

Campaign Type would be a completely sepereate filter that would have nothing to do with the dates.  You would eaither want the Campaign Type as a column in your main data table or have a Campaign table that has the field Campaign Type in it an that links to your main data table.

amitchandak
Super User
Super User

@MrKrukauskas , depending on how you want to choose the date you need on one or two date table.

Like if you need the same date range then you have join with one date table. One active and one inactive join. And use relation to activate join.

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

 

In case you need a different date, You need to two date dimension. And in your formula, you need to all for the other date. Or you can use one of the date tables as disconnected and try .

Refer to this example. this done for one date. But you have to do for two dates

 

https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

 

 

jdbuchanan71
Super User
Super User

@MrKrukauskas 

I think what you will need is 2 date lists, one linked to each field [Data Load Date] and [Historical Date]
2020-06-26_18-59-06.png

You use the dates from those 2 tables in the slicers and write the measures so the [Data Load Amonut] ignores the filters from the 'Historical Dates' table and vice versa.

Total Amount = SUM ('Table'[Amount] )
Data Load Amonut = CALCULATE( [Total Amount],ALL('Historical Dates') )
Historical Amount = CALCULATE( [Total Amount],ALL('Data Load Dates') )
Difference = [Data Load Amonut] - [Historical Amount]

2020-06-26_19-01-54.png

On both of the date slicers I also added a filter where [Total Amount] is not blank so that only dates with an amount would show in the list.

I have attached my sample file for you to look at so you can see how I made the two date tables. 

I try to do the same thing, but I cant. Could you help me? 
My pbix is here: 
https://drive.google.com/file/d/1c5DpEI4rsoPX8U8EBepHJ9gSsSmckLmg/view 

@jdbuchanan71 I really hope you see this! Thank you so much for this explanation:

One further question: if I wanted to extend this functionality, so that I can have more than one filter - what is the best way to accomplish that? 

For example: I want to filter by Historical Date, Amount Date, and Campaign Type. Do I need to also create two separate campaign type tables? Or is there a way to add campaign type information to the historical dates and data load dates tables?


@jdbuchanan71 Thanks! Worked like a charm. Now where is that Kudos button! 😄 

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.