Forum Discussion
Switch X Axis column through a slicer filter
Hi htaunay
One method is to do someting similar to what Anonymous did here:
http://tinylizard.com/dynamically-changing-chart-axis/
In your case, you would need to start with a DateTime table with datetime/day/month/year columns, which you then unpivot, and add a column identifying the granularity. The resulting table (let's call it DateTimeGranularity) provides a many-to-many relationship between DateTime and the values you want on your axis at the different levels of granularity.
You also need to add a column to enforce sort order.
In Power BI, you can then create a bi-directional relationship between the DateTimeGranularity table and the DateTime table, so that filtering on the Time Granularity column (DateTime, Date etc) also filters the DateTime table.
I've uploaded a dummy pbix file illustrating this which should make it clearer:
https://www.dropbox.com/s/aoflh2unznifyac/DateTime%20Granularity%20Selection.pbix?dl=1
The data model looks like this:
Note: you can also use drilldown on visualizations if you have a hierarchy of axis labels - I added another tab in the file illustrating this.
Owen :)
Excellent solution OwenAuger, thanks! Just a question, how do you use the order column in your visuals afterwards?
- OwenAuger7 years ago
Super User
Hi Anonymous
Are you asking about the Time Value Order column in my sample pbix file?
That column is used as the sort-by column for Time Value Text. Since Time Value Text contains a mixture of granularities (Date, DateTime, Month and Year in my case), it is impossible to sort this column based on its own values.
So Time Value Order is not directly used in any visuals, but set as the sort-by column for Time Value Text in Modeling = > Sort by Column. I also hid it in report view as the end user has no use for it.
Regards,
Owen
- Anonymous7 years agoNot applicable
It's the Modeling -> Sort by column, thanks!