Forum Discussion

scotteh-bi's avatar
scotteh-bi
New Member
5 years ago
Solved

array to filter

Hi I have a standard column with array data like; a a,b,c b,c a hoping to create a filter - flattened for users to select single values  the filter would present as flattened and unique ...
  • edhans's avatar
    5 years ago

    In Power Query, just split this column by the comma delimiter into rows, then remove duplicates. Here is the code:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlSK1QGSOkk6yWAWjAaKxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column = _t]),
        #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Column", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column"),
        #"Removed Duplicates" = Table.Distinct(#"Split Column by Delimiter")
    in
        #"Removed Duplicates"

    Turns this:

    into this, which can be used for your slicer.

     

    How to use M code provided in a blank query:
    1) In Power Query, select New Source, then Blank Query
    2) On the Home ribbon, select "Advanced Editor" button
    3) Remove everything you see, then paste the M code I've given you in that box.
    4) Press Done
    5) See this article if you need help using this M code in your model.