Line Chart X-Axis Month Values Not Sorting Correctly In Power BI LineChart
Gents,
Today, I had an issue with month values in my line chart visual not sorting correctly. The month values were plainly text in type and it seems the line chart does not recognize it's order.
In order for these to work, I need to create a month column to explicitly include the year and retrieve the value using DateValue() function. If the measure is added in the visual, set the proper date format in Power BI desktop for the line chart to recognize the proper sequence.
Output
The solution is a bit tricky, but it works!
Today, I had an issue with month values in my line chart visual not sorting correctly. The month values were plainly text in type and it seems the line chart does not recognize it's order.
In order for these to work, I need to create a month column to explicitly include the year and retrieve the value using DateValue() function. If the measure is added in the visual, set the proper date format in Power BI desktop for the line chart to recognize the proper sequence.
MonthYear = var monthName = TRIM(GrossProfitTrend[MonthName]) Return SWITCH(monthName, "Jan", DATEVALUE(MONTH(DATE(YEAR(NOW()),1, 1)) & " " & YEAR(NOW())) , "Feb", DATEVALUE(MONTH(DATE(YEAR(NOW()),2, 1)) & " " & YEAR(NOW())) , "Mar", DATEVALUE(MONTH(DATE(YEAR(NOW()),3, 1)) & " " & YEAR(NOW())) , "Apr", DATEVALUE(MONTH(DATE(YEAR(NOW()),4, 1)) & " " & YEAR(NOW())) , "May", DATEVALUE(MONTH(DATE(YEAR(NOW()),5, 1)) & " " & YEAR(NOW())) , "Jun", DATEVALUE(MONTH(DATE(YEAR(NOW()),6, 1)) & " " & YEAR(NOW())) , "Jul", DATEVALUE(MONTH(DATE(YEAR(NOW()),7, 1)) & " " & YEAR(NOW())) , "Aug", DATEVALUE(MONTH(DATE(YEAR(NOW()),8, 1)) & " " & YEAR(NOW())) , "Sep", DATEVALUE(MONTH(DATE(YEAR(NOW()),9, 1)) & " " & YEAR(NOW())) , "Oct", DATEVALUE(MONTH(DATE(YEAR(NOW()),10, 1)) & " " & YEAR(NOW())) , "Nov", DATEVALUE(MONTH(DATE(YEAR(NOW()),11, 1)) & " " & YEAR(NOW())) , "[Dec]", DATEVALUE(MONTH(DATE(YEAR(NOW()),12, 1)) & " " & YEAR(TODAY())))
The solution is a bit tricky, but it works!
Comments
Post a Comment