Forum Discussion
Sorting X- axis based on Month-Year slicer selection
- 6 months ago
You can use
PL12M Amount = VAR MaxDate = MAX ( 'Date'[Date] ) VAR StartDate = EOMONTH ( MaxDate, -12 ) + 1 VAR MaxDupeDate = MAX ( 'Dupe Date'[Date] ) VAR Result = IF ( MaxDupeDate >= StartDate && MaxDupeDate <= MaxDate, VAR Result = CALCULATE ( SUM ( Sheet1[consum] ), SAMEPERIODLASTYEAR ( 'Dupe Date'[Date] ), REMOVEFILTERS ( 'Date' ), USERELATIONSHIP ( 'Date'[Date], 'Dupe Date'[Date] ) ) RETURN Result ) RETURN ResultI tried this in a dummy model and it worked.
You can use the technique described in https://www.sqlbi.com/articles/show-previous-6-months-of-data-from-single-slicer-selection/ to show the previous 12 months from the date in your slicer.
If you want to display just the month name on the axis rather than the year & month, you could create a new column on the Previous Dates table with a date type, the values would be the start of each month, and set the format string to be "mmm". That should give you the behaviour that you're after.
Hi johnt75 ,
Thank you for the solution, currently it is working for last 6 months.
But I have to display
last 12 months
previous last 12 months
side by side in clustered column chart based on selection of month year filter.
L12M Amount =
RETURN
Could you please help me modify the DAX to achieve the requirement?
Thank you,
SSRk
- johnt756 months ago
Super User
L12M Amount looks OK, for the previous last 12 months I think you can use
PL12M Amount = CALCULATE ( [L12M Amount], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )- SSRk6 months agoFrequent Visitor
I have tried this earlier using sameperiodlastyear(), But I am getting blank.
Could you please provide possible solutions- johnt756 months ago
Super User
Maybe it needs to use the duplicate date table, try
PL12M Amount = CALCULATE ( [L12M Amount], SAMEPERIODLASTYEAR ( 'Dim Date Dup'[Date] ) )