Forum Discussion
Mederic
2 years agoPost Patron
Compare 2 tables
Hello, I'd like to compare 2 tables, each in a different tab. I would like to compare one by 2 criteria and another by all the columns. How can I do this with Power query? Thanks in advance ...
- 2 years ago
Mederic
2 years agoPost Patron
Sorry, I meant Except and not Intersect in my message 5, I've corrected it.
- lbendlin2 years agoSuper User
- Anonymous2 years agoNot applicable
Hi Mederic
You can refer to the following solution.
I used the paramater
Then you can put the following code to advanced editor
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc27DcAwCATQXagtOWAc3Oa7BPL+a8RAinyqO/GkQxUWSICUMdNEZfQ7aoWeFFbTFsqhFnNz3ewiPy3iuo/KmR5owxJ42DC+1KO4nvH2q8zQ+wU=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, date = _t, Year = _t, Qty = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}, {"date", type text}, {"Year", Int64.Type}, {"Qty", Int64.Type}}) in #"Changed Type"let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI00jcw1DcyMDIBcqCUqalSrE60khNI2kIfXdbEGCzrDBIxx5A1NgfLuoAU6huhSZoDJWMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, date = _t, Year = _t, Qty = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}, {"date", type text}, {"Year", Int64.Type}, {"Qty", Int64.Type}}), #"Appended Query" = Table.Combine({#"Changed Type", Query1}), #"Added Custom" = Table.AddColumn(#"Appended Query", "Custom", each let a=Table.RowCount(Table.SelectRows(#"Appended Query",(x)=>x[Code]=[Code] and x[Qty]=[Qty])), b=Table.RowCount(Table.SelectRows(#"Appended Query",(x)=>x[Code]=[Code] and x[Qty]=[Qty] and x[date]=[date] and x[Year]=[Year])) in if Parameter1=1 and a>1 then 1 else if Parameter1=2 and b>1 then 1 else null), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"}), #"Removed Duplicates" = Table.Distinct(#"Removed Columns") in #"Removed Duplicates"When the paramater is equal to 1, it will filter the data by code and qty in query1 table, when the paramater equal to 2, it will filter the data by all columns in query 1 table.
equal 1.
equal 2
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.