Search code examples
powerbipowerquerypowerbi-desktop

How to filter based on the different criteria and merge 2 datasets in power query


I have 2 power query advance editor code.

Query_1

    let
    Source = ABC
    #"Filtered Rows" = Table.SelectRows( SAPS4, each [FiscalYearPeriod] <> "2023011" and [FiscalYearPeriod] <> "2023012" and not Text.StartsWith([FiscalYearPeriod], "2023013"))
    Some other steps =....
    in 
    Some other steps

Query_2

    let
    Source = ABC
    Filter Rows =  Table.SelectRows( SAPS4, each [FiscalYearPeriod] <> "2023011" and [FiscalYearPeriod] <> "2023012" and not Text.StartsWith([FiscalYearPeriod], "2023013"))
    in 
    Filter Rows

What I would like to do writing both queries into 1 query then combine them. Is there a way to do that ? many thanks in advance


Solution

  • This should give the requested result:

    let
        Tbl1 =
            let
                Source = ABC
                #"Filtered Rows" = Table.SelectRows( SAPS4, each [FiscalYearPeriod] <> "2023011" and [FiscalYearPeriod] <> "2023012" and not Text.StartsWith([FiscalYearPeriod], "2023013"))
                Some other steps =....
            in 
                Some other steps,
        Tbl2 =
            let
                Source = ABC
                Filter Rows =  Table.SelectRows( SAPS4, each [FiscalYearPeriod] <> "2023011" and [FiscalYearPeriod] <> "2023012" and not Text.StartsWith([FiscalYearPeriod], "2023013"))
            in 
                Filter Rows,
                
        Append = Table.Combine({Tbl1,Tbl2})
    in 
        Append