Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreThe FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now
Hi Team,
I am facing a chellenge to sort x-axis based on selection of filter.
Image-1
Here L12M Amount is the last 12 months data from selected month.
PL12M Amount is the previous last 12 months data from selected month.
I want to sort the X- axis month based on selection of month in slicer, if I select Feb 2022, Feb should be at the rightmost position in place of December, remaining months need to be sorted accordingly. So, ideally if we read from right to left Feb to March at the left.
Image 2 is the sorting order I want.
Thank You,
SSRk
Solved! Go to Solution.
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
Result
I tried this in a dummy model and it worked.
Hi @SSRk,
Great to hear that it's working as expected on your end!. I would suggest accepting your approach as the solution so that it can benefit others as well. It would be really helpful for others in the community who might be facing similar issues and can address them quickly.
Thanks & Regards,
Prasanna Kumar
Hi All,
Thank you for the help. The solution worked and resolved the requirement.
Hi @SSRk,
Thank you for reaching out to the Microsoft Fabric Forum Community, and special thanks to @johnt75 and @Praful_Potphode for prompt and helpful responses.
Just following up to see if the Response provided by community members were helpful in addressing the issue. if the issue still persists Feel free to reach out if you need any further clarification or assistance.
Best regards,
Prasanna Kumar
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 =
Could you please help me modify the DAX to achieve the requirement?
Thank you,
SSRk
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 =
Could you please help me modify the DAX to achieve the requirement?
Thank you,
SSRk
L12M Amount looks OK, for the previous last 12 months I think you can use
PL12M Amount =
CALCULATE ( [L12M Amount], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
I have tried this earlier using sameperiodlastyear(), But I am getting blank.
Could you please provide possible solutions
Maybe it needs to use the duplicate date table, try
PL12M Amount =
CALCULATE ( [L12M Amount], SAMEPERIODLASTYEAR ( 'Dim Date Dup'[Date] ) )
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
Result
I tried this in a dummy model and it worked.
Hi @johnt75 ,
Thank you for the solution. It is working fine for the PL12M Amount when both Year and Month are included on the X-axis. However, if the Year is removed, it shows blank.
Is it possible to get the values while keeping only Month on the X-axis? The months also need to sort automatically.
You need the year for context, but what you could maybe do is create a new date type column, set to the start of the month, but set the format string to be "mmm" so it only shows the month.
Do you mean that Year needs to be included on the X-axis for the measure to return values? Is that correct?
Hi @SSRk,
The measure needs the year information to calculate the correct values. If you use only the month name (Jan to Dec) on the X axis and remove the year, Power BI cannot tell which year the month belongs to. Because of this missing context, time intelligence functions may return blank values. A good solution is to use a date column that includes both year and month, but format it to display only the month name. This way Power BI still has the correct date context for calculations, while the visual shows only the month names.
Thanks & Regards,
Prasanna Kumar
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 21 | |
| 14 | |
| 11 | |
| 6 | |
| 5 |