Power BI Interview Questions
How do I sort a column of matrix visual in Power BI using a “Month Year” field in descending order?
I am using a “month year” field on the column of the matrix visual. How can I sort it in descending order?
On the other side, in Power BI, within a Matrix visualization, it is not possible to directly sort a column by a measure in descending order. Still, you can do this by creating a calculated column in your dataset, for example, “Month Year Sort Desc,” with the help of the RANK function. Then you can indicate this column as the sort column for the column “Month Year.” More appropriately, a new column specifically for sorting purposes should be created.
Month Year = format ([Date], "MMM-YYYY")
Month Year Sort = format ([Date], "YYYYMM")
Month Year 1= [Month Year]
Month Year sort desc = Rankx(Date, [Month Year Sort],,desc,dense)
//Full Date table Script
Date = var _tab= ADDCOLUMNS(CALENDAR(date(2019,01,01), date(2022,10,31))
,"Month Year", FORMAT([Date], "MMM-YYYY")
,"Month Year sort", FORMAT([Date], "YYYYMM")
, "Year", YEAR([Date])
,"Qtr Year" ,FORMAT([Date],"YYYY\QQ"),
"WeekDay", FORMAT([Date], "ddd")
,"Month", FORMAT([Date], "MMM")
,"Month sort", FORMAT([Date], "MM")
)
return
ADDCOLUMNS(_tab,
"Month Year 1", [Month Year],
"Month Year sort desc" , Rankx(_tab, [Month Year Sort],,desc,dense))Now create a sort by marking the “Month Year Sort Desc” column as the sort column for the “Month Year 1” column. Do this by using the “Month Year 1” column in the visual. This will make the columns within your Matrix visual to be sorted in descending order.
Matrix visual column sorted in descending order.
Add comment