Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hello, suppose I have two different excel files:
File 1: | File 2: | |||
Company | Type | Company | Type | |
AAA | A | AAA Inc. | B | |
BBB | A | BBB | B | |
CCC | A | DDD | B |
I have appended these two files into one, but I would like power bi to remove rows from File 1 if the same company is found in File 2, i.e., since BBB is found in both files, keep only BBB Type B and delete BBB Type A in my combined database. How would I go about in doing this (either using power query or DAX)?
Secondly, is there also a way to apply fuzzy matching and also get power BI to remove AAA Type A since AAA Inc. Type B exists? (suppose they are same entities but data entry issues led to this discrepancy).
I hope i'm not being too unclear. Thank you for your help
Solved! Go to Solution.
Hi, @rsbin
You want to remove obscure data as well as duplicate data (first table is removed first). Right?
Here are the steps you can refer to in Power Query Editor:
(1)This is my test data:
(2) For fuzzy data, we can first let the data get back to normal format.
We can use this M language:
= Table.TransformColumns(test, {"Company",(x)=>Text.Split(x," "){0} } )
(3)Then we can remove the duplicates between the two tables and combine the two tables (we can create a blank query and enter):
= Table.SelectRows(Sheet2 , (x)=>not List.ContainsAny({x[Company]},List.Intersect({Sheet2[Company],Sheet3[Company]}) ) ) & Sheet3
(4)Then we can meet your need , the result is as follows:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi, @rsbin
You want to remove obscure data as well as duplicate data (first table is removed first). Right?
Here are the steps you can refer to in Power Query Editor:
(1)This is my test data:
(2) For fuzzy data, we can first let the data get back to normal format.
We can use this M language:
= Table.TransformColumns(test, {"Company",(x)=>Text.Split(x," "){0} } )
(3)Then we can remove the duplicates between the two tables and combine the two tables (we can create a blank query and enter):
= Table.SelectRows(Sheet2 , (x)=>not List.ContainsAny({x[Company]},List.Intersect({Sheet2[Company],Sheet3[Company]}) ) ) & Sheet3
(4)Then we can meet your need , the result is as follows:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
I believe I have a partial solution, at least to the first part of your question. In Power Query involves using the Group By and Index functions:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnR0VNJRclSK1YlWcnJygrOdnZ3hbKAaBc+8ZD2ggBOSQgjbxcUFwo4FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Company " = _t, #"Type " = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Company ", type text}, {"Type ", type text}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Type ", Order.Descending}}),
#"Grouped Rows" = Table.Group(#"Sorted Rows", {"Company "}, {{"Count", each _, type table [#"Company "=nullable text, #"Type "=nullable text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",0)),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Custom", type any}}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Changed Type1", "Custom", {"Company ", "Type ", "Index"}, {"Custom.Company ", "Custom.Type ", "Custom.Index"})
in
#"Expanded Custom"
This was my source:
https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query
Custom.CompanyCustom.TypeCustom.Index
AAA Inc. | B | 0 |
BBB | B | 0 |
BBB | A | 1 |
DDD | B | 0 |
AAA | A | 0 |
CCC | A | 0 |
Important first step was to sort your Type column in Descending order so the "B's" come out as 0.
This then enables you to filter out the 1's from the Index Column.
Please try to see if this works for you. Then we can attack the "fuzzy logic" part of your question.
Regards,
User | Count |
---|---|
129 | |
72 | |
70 | |
58 | |
53 |
User | Count |
---|---|
190 | |
97 | |
67 | |
63 | |
54 |