Forum Discussion

ElisaJhang08's avatar
ElisaJhang08
Regular Visitor
5 years ago
Solved

If slicer is selected, then show specific column

Hi, I’m the new to power BI, and will appreciate if anyone could help me to solve this simple problem.   Scenario: There are 4 mobile brands here(1,2,3,4) All of them sell 4 kinds of mobile(iiph...
  • v-angzheng-msft's avatar
    5 years ago

    Hi, ElisaJhang08 

     

    Your table structure dictates that more filtering fields are needed to get the results you want.
    You can create a multi-field slicer and then select only the corresponding fields for example in the image below.

    Of course this solution is not what we expect, so I found a second solution, unpivot some columns in the table and then add a custom column to determine if the values are displayed or not, then we can get the result as follows:

    Now we have the desired result.

    M code:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tZYxb8IwEIX/S2YqxQmBdqyTpVMHRsQALQLUlCDaCvHva5PgvLMbBvy6RHZ0/hKfz+/efJ6oZJTsdodts1+b0XH9bp4qTc3zvK7r5mQGUzFTYzs9bXffdoHKCvN8KR+eu9WLEY+p+xgmtvwfbOVeWmpmZrOvZn/GldkFu6p/7MJHGE9grPK0Tyn8J4Gor+9IvJLMq5CXi3PpQp9sZHNc7jdu1p5Y3g9VAQkk4nQfywGWcGfiaRXQxmb82hwaXN4Grurl24er8BYxluWdQvpgvxSmduE0JGaRAqzkvbMnM1t+msrebABUCBFQYpbiLEtFOV73TsPqBHWHhi3/BzusktfQQhS9ylAopPJOofewmd5l50AH9fJ+ZJjPXkV6kGxnCuQDdRh109t7PNRr5hwo3n0OUbQgi+zkRLZ7N5MSgrKMt14eUCxR04meI2IgsRtJhyWavmNMsLol3hPQ7mxY0Jsm836slE8WtQp/FlQZDUH3jTyUZPQWfxj3WJ7wmAxgmMlY4g2b6bkB8AmoE563CL06B6qTIX94L1E0IA6ySgKXiJXe+oQMmMgX1kzadvSIkUDMIwHnG85IXBVsF+pb9nusdu+8hIMI2g6L6meSwfSaDwsrjZGsdVfFRX82mecTLg3PcxGhN6Jxh+96BNRLLY2Ld37xCw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Mobile Brand" = _t, Product = _t, #"IC-A Brand" = _t, #"IC-A Usage" = _t, #"IC-B Brand" = _t, #"IC-B Usage" = _t, #"IC-C Brand" = _t, #"IC-C Usage" = _t, #"IC-D Brand" = _t, #"IC-D Usage" = _t, #"IC Type" = _t, #"IC Brand" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Mobile Brand", Int64.Type}, {"Product", type text}, {"IC-A Brand", type text}, {"IC-A Usage", Int64.Type}, {"IC-B Brand", type text}, {"IC-B Usage", Int64.Type}, {"IC-C Brand", type text}, {"IC-C Usage", Int64.Type}, {"IC-D Brand", type text}, {"IC-D Usage", Int64.Type}, {"IC Type", type text}, {"IC Brand", type text}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Mobile Brand", "Product", "IC-A Brand", "IC-B Brand", "IC-C Brand", "IC-D Brand", "IC Type", "IC Brand"}, "Attribute", "Value"),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Unpivoted Other Columns", {"Mobile Brand", "Product", "IC Type", "IC Brand", "Attribute", "Value"}, "Attribute.1", "Value.1"),
        #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "IC-X Usage"}, {"Value", "Usage value"}, {"Attribute.1", "IC-X Brand"}, {"Value.1", "X-Brand"}}),
        #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", each Text.StartsWith([#"IC-X Usage"],[IC Type])and Text.StartsWith([#"IC-X Brand"],[IC Type])),
        #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = true))
    in
        #"Filtered Rows"

    Please refer to the attachment below for details

     

     

    Hope this helps.

     

    Best Regards,
    Community Support Team _ Zeon Zheng
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.