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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
JeroenR
Helper V
Helper V

Show previous 6 months IF is in selected (month) year

Hi all,

 

I have a slicer on my report where the Month can be selected within a year. The slicers is as follow: 

JeroenR_0-1640181964561.png

 

 

I am also using the calculation of the SQLBI page where you can display the last 6 months up until the selected month. See following link: https://www.sqlbi.com/articles/show-previous-6-months-of-data-from-single-slicer-selection/

This is all working fine and perfect but I want to change 1 thing regarding this DAX calculation. Can I change this that the last 6 months will be displayed IF it is in the selected year of the selected month. So that means that if a user has selected April 2021, it will only display the months March, Feb and Jan.

2 REPLIES 2
negi007
Community Champion
Community Champion

@JeroenR can you share your data in text format which can be copied. 




Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

Hi @negi007 , thanks for the reply. 

 

My date table looks as follow:

DateYearMonth NumMonth NameMonth YearMonth Year OrderCurrent Month
6/1/202120211JanJan 2021202101Previous Month
20/6/202120216JunJun 2021202106Previous Month
15/12/2021202112DecDec 2021202112Current Month

 

Current Month is calculated as follow:

Current Month =
IF (
AND (
YEAR ( 'Date'[Date] ) = YEAR ( NOW () - 1 ),
MONTH ( 'Date'[Date] ) = MONTH ( NOW () - 1 )
),
"Current Month",
"Previous Months"
)
 
Fact table has just a regular date column which is connected with a one to many relationship with my date table. 

Please let me know if you need further information.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

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