Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Create slicer groups by selecting columns

Hello,

I have the following table and i am trying to present the data in a stacked column visualization with grouping selectable in a slicer based on specific columns.

The X axis is the week number and the Y axis shows the number of items according to each category.

The 3 groupings should be:

1. Warehouse: Stock and Returns

2. Dock: Defective and Sold

3. Transport: Excess and Expired.

These 3 groupings should be in a slicer, so when "Warehouse" is selected, it should filter out the chart to only show Stock and Returns. Is this possible? Any help is much appreciated!

 

YearWeek numberStockReturnsDefectiveSoldExcessExpired
202213482811
2022269176210
2022325103612
2022493163512
2022556157315
2022622102311
2022778229319
2022833134713
2022963187218
20221033148914
20221127175217
20221237223621

 

The chart with the data from the table:

 

 

I have tried to make a group from the Fields area but it is not working. It should allow selecting the column names instead of showing the values in that column.

 

  • lbendlin's avatar
    lbendlin
    4 years ago

    For that to work you need to change your data model. Unpivot the source data and add the categories there.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZZDNDoIwDMdfxezMgVXn4K4voAdjCAeFmhAUDaDx8e22Ninx8M/68WvXtqrMGS+jycwJsV8N78cVg3ecn01P7wHn9zhMZO3whs3cfTBkn/eWnv23wWmKxqsbsTV1VhnIAShkSWvShlSQgF9rNRW0JZUh49mJ5bnG1hx1KZMCAbWgsQ13Clm7ZcP9YY4VGwTDS43TmIwC8qlMslzBs+KSoCcoNVZwNGbkMD45Civ544gVjEBy9HVz3U5uXCZHc5bLvRzYST+/4GQ3L1vIhYGWrX8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t]),
        #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Year", "Week number"}, "Channel", "Value"),
        #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Category", each if List.Contains({"Stock","Returns"},[Channel]) then "Warehouse" else if List.Contains({"Defective","Sold"},[Channel]) then "Dock" else "Transport"),
        #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Category", type text}, {"Value", Int64.Type}})
    in
        #"Changed Type"

    see new version attached

3 Replies

  • Instead of the three groups you need to create three measures.  If you want you can also create a disconnected table with these three choices and then tie the measure result to the selected value. Or use the fancy new Field Parameters.

    see attached.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi lbendlin Thanks for your reply! The new Field Parameters escaped me! But is it possible to show the categories for each grouping in a legend?

       

      For example, when "Warehouse" is selected, the graph should look as follows:

       

      • lbendlin's avatar
        lbendlin
        Super User

        For that to work you need to change your data model. Unpivot the source data and add the categories there.

         

        let
            Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZZDNDoIwDMdfxezMgVXn4K4voAdjCAeFmhAUDaDx8e22Ninx8M/68WvXtqrMGS+jycwJsV8N78cVg3ecn01P7wHn9zhMZO3whs3cfTBkn/eWnv23wWmKxqsbsTV1VhnIAShkSWvShlSQgF9rNRW0JZUh49mJ5bnG1hx1KZMCAbWgsQ13Clm7ZcP9YY4VGwTDS43TmIwC8qlMslzBs+KSoCcoNVZwNGbkMD45Civ544gVjEBy9HVz3U5uXCZHc5bLvRzYST+/4GQ3L1vIhYGWrX8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t]),
            #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
            #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Year", "Week number"}, "Channel", "Value"),
            #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Category", each if List.Contains({"Stock","Returns"},[Channel]) then "Warehouse" else if List.Contains({"Defective","Sold"},[Channel]) then "Dock" else "Transport"),
            #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Category", type text}, {"Value", Int64.Type}})
        in
            #"Changed Type"

        see new version attached