Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Filter One Table based on Another Table in Power Query only

Hello Everyone,

 

Sales Table:

YearCategorySalesprofit
2018A50050
2018B20020
2018C12012
2018A40040
2018B30030
2019C15015
2019A52052
2019B22022
2019C13013

 

Profit Filter Table :

YearProfit_Filter
201830
201915

 

I want to filter my "Sales table: based on "Profit filter table".

Filter condition :
Remove rows from "Sales table" where profit is below of "Profit_filter" column value.

 

Outout :

YearCategorySalesprofit
2018A50050
2018A40040
2018B30030
2019C15015
2019A52052
2019B22022

 

I need to apply this logic in Power Query only.  I do not want to merge two tables.

Thank You
Vipin Bharti

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi Vipin,

The requirement to not merge seems arbitrary. Merge is one of the faster methods for comparing data in PQ. Also, the merge can be done and still be made to appear that no merge took place.  The sample below demonstrates this ability and can be used should you relax the merge requirement.

 

Regards,

Mike

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc4xCsAwCIXhuzhnMM8I7dj2GCH3v0bsgwZLBh0+5MfeBVoPKXLFuCq3jLL8jgEdP39iKpQ7+9tpvG9bx+i2/Pw6zo5n5z/sO7LzHzqwdYwdkzEm", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Year = _t, Category = _t, Sales = _t, profit = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Category", type text}, {"Sales", Int64.Type}, {"profit", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Year"}, ProfitFilter, {"Year"}, "ProfitFilter", JoinKind.Inner),
    #"Filtered Rows" = Table.SelectRows(#"Merged Queries", each ([profit] <= [ProfitFilter][Profit_Filter]{0}?)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"ProfitFilter"})
in
    #"Removed Columns"

 

View solution in original post

2 REPLIES 2
AnkitBI
Solution Sage
Solution Sage

Hi @Anonymous , as Mike mentioned Merge is one of the preffered option. To get the result without merge, try below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc4xCsAwCIXhuzhnMM8I7dj2GCH3v0bsgwZLBh0+5MfeBVoPKXLFuCq3jLL8jgEdP39iKpQ7+9tpvG9bx+i2/Pw6zo5n5z/sO7LzHzqwdYwdkzEm", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Year = _t, Category = _t, Sales = _t, profit = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Category", type text}, {"Sales", Int64.Type}, {"profit", Int64.Type}}),
    Custom1 = Table.AddColumn(#"Changed Type","Test",each List.IsEmpty(Table.SelectRows(ProfitFilter,(a) => a[Year] = [Year] and [profit] >= a[Profit_Filter])[Profit_Filter])),
    #"Filtered Rows" = Table.SelectRows(Custom1, each ([Test] = false))
in
    #"Filtered Rows"

 

Thanks
Ankit Jain
Do Kudo the response if it seems good and helpful.

Anonymous
Not applicable

Hi Vipin,

The requirement to not merge seems arbitrary. Merge is one of the faster methods for comparing data in PQ. Also, the merge can be done and still be made to appear that no merge took place.  The sample below demonstrates this ability and can be used should you relax the merge requirement.

 

Regards,

Mike

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc4xCsAwCIXhuzhnMM8I7dj2GCH3v0bsgwZLBh0+5MfeBVoPKXLFuCq3jLL8jgEdP39iKpQ7+9tpvG9bx+i2/Pw6zo5n5z/sO7LzHzqwdYwdkzEm", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Year = _t, Category = _t, Sales = _t, profit = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Category", type text}, {"Sales", Int64.Type}, {"profit", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Year"}, ProfitFilter, {"Year"}, "ProfitFilter", JoinKind.Inner),
    #"Filtered Rows" = Table.SelectRows(#"Merged Queries", each ([profit] <= [ProfitFilter][Profit_Filter]{0}?)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"ProfitFilter"})
in
    #"Removed Columns"

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors