Forum Discussion

htaunay's avatar
htaunay
Icon for Microsoft Employee rankMicrosoft Employee
10 years ago

Switch X Axis column through a slicer filter

Hi PowerBI experts,

 

I am currently working with a dataset where each line represents information of a specific hour, and would like to plot such data grouped by days, weeks or months, given the users interest.

 

The grouping of the data is achieved by creating custom columns (DAY, WEEK and MONTH) and setting such columns as the X Axis of my plots. However, in this solution I am forced to have 3 different plots for each time slice, when the ideal solution would involve a slicer filter where I could select a time slice and the plot would update automatically.

 

Specifically, and function/trigger that could alter a plot's X Axis through a checkbox would work for me. Is this type of behavior supported by PowerBI?

 

Thanks in advance!

23 Replies

  • 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 :)

    • efigoldman's avatar
      efigoldman
      Frequent Visitor

      Great post.

      Are you sure there is no other way? like we used to do with MDX? by replacing sets?

      • vanessa's avatar
        vanessa
        Icon for Post Patron rankPost Patron

        Any work around for this, using DAX with SWITCH?

    • mws5872's avatar
      mws5872
      Icon for Helper II rankHelper II

      this works great except in cases where you add weekend date and quarter and the dates correspond with a month end for example.

       

      Then you are not allowed to sort by the column because it does not have a unique value. any ideas?

       

      the Datekey is joined to the date table but the time value order is what is being used to sort. you see it will not work as there is not a unique value. 

       

       

      AttributeDateControlDateKeyValueTime Value Order
      Month18/1/2021 0:008/1/20215137
      WeekEnd08/1/2021 0:008/1/20214935
    • mws5872's avatar
      mws5872
      Icon for Helper II rankHelper II

      OwenAuger Thanks for this idea it works very well except in the situation I ran into. you can see my post below. thanks for this !

      • Seward12533's avatar
        Seward12533
        Icon for Solution Sage rankSolution Sage

        Try using multiple charts that you selectively show/hide with bookmarks and selection pane and use buttons to switch between them. I use this method extensively.

         

        So you woudl have 5 version of the chart and create bookmarks with only one of these shown. Then create buttons linked to those bookmarks. (tip when saving bookmark be sure to uncheck the data propery of the bookmark so it only remembers which visuals to display and does not reset any filters.