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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

How to calculate difference between data of two selected dates.

Dear Support Team,

I really need your help to solve my requirement. Thank you so much in advance. I have searched everywhere but not able to solve it.

My data source is as follows. Only one table, loaded from an excel (see below image).

pbi_Issue1.png

I have to create 3 visuals (shown below) from the above data table.

  • Visual 1 shows the data for the first date only (chosen by date slicer 1).
  • Visual 2 shows the data for the second date only (chosen by date slicer 2).
  • Visual 3 shows the difference (Amount) calculated between two dates, by City and Customer. 

 Below is the complete report, I would like to implement. 

pbi_issue2.png

3 REPLIES 3
TomMartens
Super User
Super User

Hey @Anonymous ,

 

this is not as simple as it may seem, this is because of the following.

DAX does not provide any means to determine the source of the filtering happening to table. This means if there are to slicers with the same input, it may be possible to make the slicer act as they are independent by adjusting the interaction settings.

 

But it's not possible to determine what date slicer has been used to filter the the table that contains the column, that is "feeding the slicer".

One question, that is not answered, what happens if more than 2 dates are uses?

 

I would write my measure like this. Assuming that VALUES(...[Date]) just contains 2 dates, I would use MAXX(VALUES(...) , '...'[date]) to determine one date and MINX to determine the 2nd date, and store these dates to 2 variables.

 

Then I would use these variables to calculate 2 other varialbles like so:
var value1 = CALCULATE(SUM('...'[Amount] , '...'[Date] = maxxdate)
var value2 = CALCULATE(SUM('...'[Amount] , '...'[Date] = minxdate)

 

The final result is than just the difference between value1 and value2.

 

I guess it's possible, that the 3rd visual will show a result that you might not expect.

 

Hopefully this provides you with some ideas.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom - well your solution was helpful for me but how to implement the same when the report is to be quarterly ?

Anonymous
Not applicable

Hi @TomMartens , 

 

Thank you for sharing your idea. However, It didn't help me to achieve the complete solution that I was looking for but using your idea, I am able to solve it differently and implement something similar. Here is how I did it.

  • Instead of using two date slicers, now I use only one slicer so I am able to catch the selected dates and use selected dates into a measure.
  • In order to make sure, not more than two dates get selected, I wrote logic to throw an error when selected more than two dates because the main purpose of this report to compare two dates data and calculate the difference amount.
  • Below are my Measure and reports (Output). 

Measure.png 

Rpt.png

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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