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
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
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.