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
MCacc
Helper III
Helper III

Calculation for the three months before the current month

Hello, 

 

I'd like to create  a DAX wich shows the value for the three months before the current one. 

 

Example:

DATE              VALUE

7th April           18

18th April         20

17th May          48

28th May          20

11th June          38

18th June          20

11th July           8

18th July          20

Because July is not over yet, I need the sum for the months April, May, June , therefore 164.

I have to put this measure in a line chart where I have my date on the x axis. 

 

I tried this measure but  the line chart is still showing July:

CALCULATE ([My Measure], all(Table_Date),
FIRSTDATE (
DATESINPERIOD (
Table_Date[Date],
LASTDATE ( Table_Date[Date]),
-3,
MONTH
)
)
)

 

Any ideas? 

 

Thank you

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@MCacc , when you use date table with max and lastdate and no date is selected, it can date the last date of the calendar

 

Try like

 

CALCULATE ([My Measure], all(Table_Date),
FIRSTDATE (
DATESINPERIOD (
Table_Date[Date],
eomonth(today() ,-1) ,
-3,
MONTH
)
)
)

 

 

Or

 

Last Month Today =
var _min = eomonth(today(),-2)+1
var _max = eomonth(today(),-1)
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

3rd Last Month Today =
var _min = eomonth(today(),-4)+1
var _max = eomonth(today(),-3)
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

 Last 3 Months Today =
var _min = eomonth(today(),-4)+1
var _max = eomonth(today(),-1)
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

https://medium.com/chandakamit/cheat-sheet-power-bi-time-intelligence-formulas-using-today-654f26e27...

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@MCacc , when you use date table with max and lastdate and no date is selected, it can date the last date of the calendar

 

Try like

 

CALCULATE ([My Measure], all(Table_Date),
FIRSTDATE (
DATESINPERIOD (
Table_Date[Date],
eomonth(today() ,-1) ,
-3,
MONTH
)
)
)

 

 

Or

 

Last Month Today =
var _min = eomonth(today(),-2)+1
var _max = eomonth(today(),-1)
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

3rd Last Month Today =
var _min = eomonth(today(),-4)+1
var _max = eomonth(today(),-3)
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

 Last 3 Months Today =
var _min = eomonth(today(),-4)+1
var _max = eomonth(today(),-1)
return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

https://medium.com/chandakamit/cheat-sheet-power-bi-time-intelligence-formulas-using-today-654f26e27...

Thank you! The last one worked just fine..

 

🙂

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.