Forum Discussion

Merleau's avatar
Merleau
Icon for Helper II rankHelper II
6 years ago
Solved

DAX: Delete empty columns after filtering

Hello, I have a table in my report similar to this: ID Zipcode Red Blue Pink Magneta Id1 20T00   Blue     Id2 20T00 Red   Pink   Id3 50R30 ...
  • VasTg's avatar
    6 years ago

    Merleau 

     

    You have to modify your input table to get what you want.

    Input:

     

    You should transform the input table into this.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nQxVNJRMjIIMTAA0kDklFOaCmEpxeqA5I2Q5INSUyByAZl52QglxkCmqUGQMdQIhLxvYnpeakkiVJkJWFmgMYpJCFNMkaTRHBILAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, Zip = _t, Red = _t, Blue = _t, Pink = _t, Magneta = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Zip", type text}, {"Red", type text}, {"Blue", type text}, {"Pink", type text}, {"Magneta", type text}}),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID", "Zip"}, "Attribute", "Value"),
        #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Color"}}),
        #"Filtered Rows" = Table.SelectRows(#"Renamed Columns", each ([Value] <> ""))
    in
        #"Filtered Rows"

     

     

    Follow the Unpivot and filtered steps.

    Then create a matrix with stepped layout off as below

     

    When you filter the zip, you get the expected output.

    The idea is to keep the color columns as values to not show the column altogether.

     

    If it helps, mark it as a solution

    Kudos are nice too