Forum Discussion

jorgeslzr's avatar
jorgeslzr
Frequent Visitor
5 years ago
Solved

Filtering edit query

Hi, I have a data source that has a column with Store_ID, Date, and Status: STORE_ID DATE STATUS A1 01/01 Not activated A1 01/01 Activated B1 01/01 Activated C2 01/02 Not Ac...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi jorgeslzr ,

    You can edit the applied codes in Advanced Editor to achieve it:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lEyMjAy0DfUBzH98ksUEpNLMssSS1JTlGJ1MFU4osg64ZV1NkLIGmGaHgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [STORE_ID = _t, DATE = _t, STATUS = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"STORE_ID", type text}, {"DATE", type date}, {"STATUS", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"DATE", "STORE_ID"}, {{"Count", each Table.RowCount(Table.Distinct(_)), Int64.Type}, {"Details", each _, type table [STORE_ID=nullable text, DATE=nullable date, STATUS=nullable text]}}),
        #"Expanded Details" = Table.ExpandTableColumn(#"Grouped Rows", "Details", {"STATUS"}, {"Details.STATUS"}),
        #"Filtered Rows" = Table.SelectRows(#"Expanded Details", each ([Details.STATUS] = "Not activated") and ([Count] = 1))
    in
        #"Filtered Rows"

    You can also refer the following blog to achieve it:

    Grouping in Power Query; Getting The Last Item in Each Group

    Best Regards

    Rena