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
Power5
Helper IV
Helper IV

How do I get the difference of balances between dates?

Hello,

 

I am trying to figure out a way to calculate the difference in balances when I select multiple dates in my slicer. For example, if balance in 12/31/2023 was 11m and balance in 1/31/2024 is 12m I would like to see a difference of 1m be the output. 

Power5_0-1708987197851.png

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table and a retionship (Many to One and Single) from the ProdDate column of your Data Table to the Date column of the Calendar Table.  To your slicer, drag the Date column from the Calendar Table and select 2 dates.  Write these measures

Total = sum(Data[Amount])

Total on first date = calculate([Total],datesbetween(Calendar[date],min(calendar[date]),min(calendar[date])))

Total on second date = calculate([Total],datesbetween(Calendar[date],max(calendar[date]),max(calendar[date])))

Variance = [Total on first date]-[Total on second date]

Hope this helps.


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

View solution in original post

7 REPLIES 7
_AAndrade
Super User
Super User

It's not wrong the number on the card visual. It's the context where DAX is being evaluated.
If I select 31-01-2024 date on my table the card will show the correct number like this:

_AAndrade_0-1708991218373.png

The Dax measure I used it's to calculate the Balance of the previous month of each date that you have on the visual. It's working to the table matrix and bar chart.







Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table and a retionship (Many to One and Single) from the ProdDate column of your Data Table to the Date column of the Calendar Table.  To your slicer, drag the Date column from the Calendar Table and select 2 dates.  Write these measures

Total = sum(Data[Amount])

Total on first date = calculate([Total],datesbetween(Calendar[date],min(calendar[date]),min(calendar[date])))

Total on second date = calculate([Total],datesbetween(Calendar[date],max(calendar[date]),max(calendar[date])))

Variance = [Total on first date]-[Total on second date]

Hope this helps.


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

I fixed the measures. However; my card that I want to show for the variance does not pull back correct number. IT only returns the balance for the max date but not the difference between the min and max date selected in slicer. 

See Below:

Power5_0-1709054648392.png

 

Share the download link of the PBI file and show the problem there clearly.


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

Total on first date and total on second date are invalid functions. It says "too few arugments were passed to the DATESBETWEEN function.

_AAndrade
Super User
Super User

Hi,
As far as I can see, you are using implicit measures, and to do what you want you need to use explicit measures.
I did a quick example in my pbi desktop and have this results:

_AAndrade_0-1708988792734.png

I'm using this two measures:

_AAndrade_1-1708988831237.png_AAndrade_2-1708988845622.png

 

 







Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




It returns this. I want the 116,899.82 to show up in the card but it shows the grand total instead in the card which is way off by the way.

Power5_0-1708990846703.png

 

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.