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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Need help with Dax to display Previous Month Name in a Card based no a Slicer selection

I have Created a DAX to display the Slicer Filtered Value in Card, but I am not able to write the same DAX to display Previous Month Name, Previous Quarter Name, or Previous Year Name based on the slicer selection.
For Eg: If Slicer is filtered for Feb, the Previous Month's Card should show Jan, similarly for Quarter and Year.
Dax for Current Selection:
Selected date Dynamic Title =
var curr_yr = YEAR(TODAY())
return
IF(ISFILTERED('Calendar Table'[Date].[Month]),
CONCATENATEX(VALUES ('Calendar Table'[Date].[Month]),'Calendar Table'[Date].[Month],",") & " " & VALUES('Calendar Table'[Date].[Year]),
IF(ISFILTERED('Calendar Table'[Date].[Quarter]),
CONCATENATEX(VALUES ('Calendar Table'[Date].[Quarter]),'Calendar Table'[Date].[Quarter],",") & " " & VALUES('Calendar Table'[Date].[Year]),
IF(ISFILTERED('Calendar Table'[Date].[Year]),
CONCATENATEX(VALUES ('Calendar Table'[Date].[Year]),'Calendar Table'[Date].[Year],","),
IF(ISFILTERED('Calendar Table'[Date]),
CONCATENATEX(VALUES ('Calendar Table'[Date]),'Calendar Table'[Date],","),
"Current Year"))))
The Goal here is to display 2 cards, one with current selection(I think I have achieved that) and the other one with previous names (Month, Quarter and Year) based on the selection on the slicer.
 
Thanks
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Make sure name you want to display is avaiable as columns in date table

 

Month Name = CALCULATE(max('Date'[Month Year]),DATESMTD('Date'[Date]))
last Month Name = CALCULATE(max('Date'[Month Year]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
Last Qtr Name = CALCULATE(max('Date'[Qtr Year]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))
Last year Name = CALCULATE(max('Date'[Year]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

 

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 :radacad sqlbi My Video Series Appreciate your Kudos.

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Make sure name you want to display is avaiable as columns in date table

 

Month Name = CALCULATE(max('Date'[Month Year]),DATESMTD('Date'[Date]))
last Month Name = CALCULATE(max('Date'[Month Year]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
Last Qtr Name = CALCULATE(max('Date'[Qtr Year]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))
Last year Name = CALCULATE(max('Date'[Year]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

 

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 :radacad sqlbi My Video Series Appreciate your Kudos.

Anonymous
Not applicable

Thanks, @amitchandak, this works perfectly. Really appreciate your help.

 

Thanks

Sathwik

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors