0

I have a list of elemental impurities in power query which I wish to filter according to whether or not they exist on another list known as the prop65 list.

The screenshot below shows a simplified example of what I am trying to achieve.

enter image description here

I appreciate that using formulas However I don't know how to achieve this using a Power query solution. If anyone know how to achieve this it would be appreciated.

Data shown:

Aluminium 33.885
Antimony 0.6777
Arsenic 3.5064
Barium 2.259
Boron 1.3554
Bromoform 0.555
Cadmium 3.18895
Chromium 0.33885
Cobalt 1.1295
Copper 0.4518
Indium 0.4518

Simplified Prop65 List
Arsenic
Bromoform
Cadmium
Furan
Lead
Nafenopin
2
  • See if this YT Video helps and this .. you can create another query to filter the first one. Commented Jul 13, 2021 at 10:42
  • 3
    Looks like you just want to merge the two queries using an inner join to me. Commented Jul 13, 2021 at 10:47

1 Answer 1

2

Here is one way to do that:

  • Read in the two tables
  • Do an Inner Join
let
    //get original data
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    data  = Table.TransformColumnTypes(Source,{{"Impurity", type text}, {"Amount (ppm)", type number}}),

    //get Filter
    Source2 = Excel.CurrentWorkbook(){[Name="Prop65"]}[Content],
    filter = Table.TransformColumnTypes(Source2,{"Simplified Prop65 List", Text.Type}),

    //Join them
    filteredData = Table.Join(data,"Impurity", filter, "Simplified Prop65 List",JoinKind.Inner),

    //Remove unneeded column
    #"Removed Columns" = Table.RemoveColumns(filteredData,{"Simplified Prop65 List"})
in
    #"Removed Columns"

enter image description here

Another method would be a filter (Table.SelectRows) method, but it may be slower with a large dataset. At least, in a single instance where I had an opportunity to compare, the Table.Join method was faster on a 100,000 row data set.

let
    //get original data
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    data  = Table.TransformColumnTypes(Source,{{"Impurity", type text}, {"Amount (ppm)", type number}}),

    //get Filter
    Source2 = Excel.CurrentWorkbook(){[Name="Prop65"]}[Content],
    filter = Table.TransformColumnTypes(Source2,{"Simplified Prop65 List", Text.Type})[#"Simplified Prop65 List"],

    //filter the rows
    filteredData = Table.SelectRows(data, each List.Contains(filter,[Impurity]))
in
    filteredData
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.