Forum Discussion
Filter table based on other filtered table
- Anonymous4 years ago
You really can do what AlexisOlson advises, but if you'd rather use List.Contains, that's legit as well, like if you don't want the values from Table A (but my first thought was Inner Join as well):
Table.SelectRows(TableB, each List.Contains(List.Buffer(List.Distinct(TableA[FieldX])), [FieldX]))
--Nate
- 4 years ago
Thanks for this code.
I copied it very carefully, substituting the real names for the dummy ones, but failed dismally.
More by happenstance than skill, I arrived at
Table.SelectRows(dbo_TableB, each List.Contains(List.Buffer(List.Distinct(TableA[FieldX])), [FieldX]))
I can see what's happening, and why this is doing what I need.
dbo_TableB is referring to the underlying table in the database. That's good.
TableA is teferring to the filtered TableA which exists after the steps in the M code. That's also good.
Reading the M code as functional programming, and referring to the docs for each method, makes sense of it all. I've attached the real code for information.
let Source = Sql.Database("redwinghealthserver.database.windows.net", "SMIPHC"), dbo_PrimaryPatientObservation = Source{[Schema="dbo",Item="PrimaryPatientObservation"]}[Data], JustThePatients = Table.SelectRows(dbo_PrimaryPatientObservation, each List.Contains(List.Buffer(List.Distinct(PrimaryPatient[NHSNumber])), [NHSNumber])) in JustThePatients - 4 years ago
You can use that as the table to join with.
= Table.NestedJoin( Source, {"FieldX"}, Table.SelectRows(TableA, each [P] = P), {"FieldX"}, "TableA", JoinKind.Inner )
You really can do what AlexisOlson advises, but if you'd rather use List.Contains, that's legit as well, like if you don't want the values from Table A (but my first thought was Inner Join as well):
Table.SelectRows(TableB, each List.Contains(List.Buffer(List.Distinct(TableA[FieldX])), [FieldX]))
--Nate
- DonnaKelly4 years agoRegular Visitor
Thanks for this code.
I copied it very carefully, substituting the real names for the dummy ones, but failed dismally.
More by happenstance than skill, I arrived at
Table.SelectRows(dbo_TableB, each List.Contains(List.Buffer(List.Distinct(TableA[FieldX])), [FieldX]))
I can see what's happening, and why this is doing what I need.
dbo_TableB is referring to the underlying table in the database. That's good.
TableA is teferring to the filtered TableA which exists after the steps in the M code. That's also good.
Reading the M code as functional programming, and referring to the docs for each method, makes sense of it all. I've attached the real code for information.
let Source = Sql.Database("redwinghealthserver.database.windows.net", "SMIPHC"), dbo_PrimaryPatientObservation = Source{[Schema="dbo",Item="PrimaryPatientObservation"]}[Data], JustThePatients = Table.SelectRows(dbo_PrimaryPatientObservation, each List.Contains(List.Buffer(List.Distinct(PrimaryPatient[NHSNumber])), [NHSNumber])) in JustThePatients