Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Filter sum column by category

I want to create a slicer of categories so that I can see the evolution of the portfolio by period. Any idea how to do it for the example below?

 

PeriodPortfolio (A+B+C)Category ACategory BCategory C
jan-191406490455461
feb-191297485361451
mrt-19941339280322
apr-191030460321249
mei-19915190316409
jun-19569164293112
jul-19929192368369
aug-191429458471500
sep-191155405300450
okt-19778123290365
nov-19951415344192
dec-19886207404275

 

  • Go into Power Query, get rid of the sum column, then unpivot the individual category columns so you have:

     

    period - category - value

    jan-19 - a - 490

    jan-19 - b - 455

    jan-19 - c - 461

    feb-19 - a - 485

     

    etc - the category column can then just be dropped into a slicer as you want

  • Hi Anonymous ,

     

    1. Unpivot the table.

     

    M code for your reference.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("RZC5bgMxDET/ZWsbIEXqYGkgSOEijUvDRRIsgiCHDSPO91sz2k0aSiCfRjM8HieN7f75e9pM6lL64SGoOaMWnU4bMo/zC5gUFf2GqfUpyMF8XX+2Gr0RjrYZ7qlBzFJaZXaXK2TE+EkZU/DJY8jM74uM4g+lG1M6k1hl9jc4zgWgFsf7MNw1/SOfUElEItFvY/1T2d3emJuMZ0y9wkwWWZnDfKHu2Icwt4wNDeb8seSutXFDRje0XfIq83T+hZvMjTGZuS/OFuRhfu2N1hA1CdcsTFa7yukO", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Period = _t, #"Portfolio (A+B+C)" = _t, #"Category A" = _t, #"Category B" = _t, #"Category C" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Period", type text}, {"Portfolio (A+B+C)", Int64.Type}, {"Category A", Int64.Type}, {"Category B", Int64.Type}, {"Category C", Int64.Type}}),
        #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Portfolio (A+B+C)"}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Period"}, "Attribute", "Value")
    in
        #"Unpivoted Other Columns"

     

     

    2. Then we can see the evolution of the portfolio by period.

     

    For more details, please check the pbix as attached.

     

3 Replies

  • jthomson's avatar
    jthomson
    Solution Sage

    Go into Power Query, get rid of the sum column, then unpivot the individual category columns so you have:

     

    period - category - value

    jan-19 - a - 490

    jan-19 - b - 455

    jan-19 - c - 461

    feb-19 - a - 485

     

    etc - the category column can then just be dropped into a slicer as you want

  • Anonymous's avatar
    Anonymous
    Not applicable

    As suggested, remove the Portfolio column and unpivot the table on Period, then use the Category column in the slicer.

  • v-frfei-msft's avatar
    v-frfei-msft
    Community Support

    Hi Anonymous ,

     

    1. Unpivot the table.

     

    M code for your reference.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("RZC5bgMxDET/ZWsbIEXqYGkgSOEijUvDRRIsgiCHDSPO91sz2k0aSiCfRjM8HieN7f75e9pM6lL64SGoOaMWnU4bMo/zC5gUFf2GqfUpyMF8XX+2Gr0RjrYZ7qlBzFJaZXaXK2TE+EkZU/DJY8jM74uM4g+lG1M6k1hl9jc4zgWgFsf7MNw1/SOfUElEItFvY/1T2d3emJuMZ0y9wkwWWZnDfKHu2Icwt4wNDeb8seSutXFDRje0XfIq83T+hZvMjTGZuS/OFuRhfu2N1hA1CdcsTFa7yukO", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Period = _t, #"Portfolio (A+B+C)" = _t, #"Category A" = _t, #"Category B" = _t, #"Category C" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Period", type text}, {"Portfolio (A+B+C)", Int64.Type}, {"Category A", Int64.Type}, {"Category B", Int64.Type}, {"Category C", Int64.Type}}),
        #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Portfolio (A+B+C)"}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Period"}, "Attribute", "Value")
    in
        #"Unpivoted Other Columns"

     

     

    2. Then we can see the evolution of the portfolio by period.

     

    For more details, please check the pbix as attached.