Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi all
I have a date slicer and I need to have a column with a 2 month lag from that slicer's date selected.
Example, slicer is December 2019 (format MMMM YYYY).
Then the column should reflect: october 2019.
Currently I have this and I dont know how to get it right:
As seen the column name 2PY date is reflecting December 2019, but should show october 2019.
Thanks in advance!
Solved! Go to Solution.
Hi,
According to your description, i create a table to test:
Then, i create a measure to show selected date's previous two month date:
2PY Date on selected date =
VAR a =
MONTH ( SELECTEDVALUE ( 'Table'[Date] ) ) - 2
RETURN
SWITCH (
TRUE,
a > 0, DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ), a, DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) ),
a = 0, DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ) - 1, 12, DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) ),
a = -1, DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ) - 1, 11, DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) )
)Choose date as a slicer and when you choose one date, it shows:
Best Regards,
Giotto Zhi
If you simply need to be 2 months behind. You can use column to. In this pbix. I create both column and measure example
https://www.dropbox.com/s/e2wkpei0ilvcw3o/DateBefore2Month.pbix?dl=0
before 12 months = CALCULATE(Max(Sales[Sales date]),dateadd('Date'[date],-12,MONTH))
before 12 months = CALCULATE(Max(Sales[Sales date]),dateadd('Date'[date],-1,YEAR))
Hi,
According to your description, i create a table to test:
Then, i create a measure to show selected date's previous two month date:
2PY Date on selected date =
VAR a =
MONTH ( SELECTEDVALUE ( 'Table'[Date] ) ) - 2
RETURN
SWITCH (
TRUE,
a > 0, DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ), a, DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) ),
a = 0, DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ) - 1, 12, DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) ),
a = -1, DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ) - 1, 11, DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) )
)Choose date as a slicer and when you choose one date, it shows:
Best Regards,
Giotto Zhi
Loos nice! If you dont mind, can you please explain the dax logic (for my learning and future scenarios)
2PY Date on selected date =
VAR a =
MONTH ( SELECTEDVALUE ( 'Table'[Date] ) ) - 2 // The -2 is for?
RETURN
SWITCH (
TRUE, // what does the true do?
a > 0, DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ), a, DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) ), // what is this for?
a = 0, DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ) - 1, 12, DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) ), // what is this for?
a = -1, DATE ( YEAR ( SELECTEDVALUE ( 'Table'[Date] ) ) - 1, 11, DAY ( SELECTEDVALUE ( 'Table'[Date] ) ) ) // what is this for?
)
I added the questions inside the code.
Thanks a lot.
Hi,
The '-2' in formula is to calculate the previous two month.
The 'true' means all the formula behind it is one-to-one relationship, as in formula, if a>0 is right, it will return the date behind it.
The three checking formulas are to check the boundary of each year, if one month-2<0, the corresponding year will -1 and the month will become Nov or Dec.
Best Regards,
Giotto Zhi
You can use a measure like this. Make sure you have calendar table and that is marked as date
before 2 months = CALCULATE(sum(Sales[Sales Amount]),dateadd('Date'[date],-2,MONTH))
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.
Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges
Connect on Linkedin
Hi @amitchandak
Why did you use a measure of sales?
In this particular case it's just a date what I need.
Thanks!!
before 2 months = CALCULATE(Max(Sales[Sales date]),dateadd('Date'[date],-2,MONTH))
In Case if date, take max of date. At line level it will give the same date 2 month before.
If you simply need to be 2 months behind. You can use column to. In this pbix. I create both column and measure example
https://www.dropbox.com/s/e2wkpei0ilvcw3o/DateBefore2Month.pbix?dl=0
looks perfect, one final thing. If I want to get it for the previous year, should i just do a "-365" in the end of the formula? or is there a more elegant dax code.
Thanks a lot @amitchandak
before 12 months = CALCULATE(Max(Sales[Sales date]),dateadd('Date'[date],-12,MONTH))
before 12 months = CALCULATE(Max(Sales[Sales date]),dateadd('Date'[date],-1,YEAR))
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 59 | |
| 43 | |
| 42 | |
| 23 | |
| 17 |
| User | Count |
|---|---|
| 190 | |
| 122 | |
| 96 | |
| 66 | |
| 47 |