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.
Hi there,
I'm looking to Remove or Include columns based on their presence in a lookup table. I've seen several articles on removing columns that contain specific terms in the Column name but I'm struggling to adapt to loop through or search and match against row values in another table.
Example:
Table to remove cols:
Firstname | Surname | Address 1 | Address 2 |
data | data | data | data |
Target columns:
Column Name | Keep/Remove |
Firstname | Keep |
Surname | Keep |
Address 1 | Remove |
Address 2 | Remove |
Target output:
Firstname | Surname |
data | data |
Any help appreciated.
Thanks,
Steve
Solved! Go to Solution.
Hi @StevenMorgan ,
If this can help:
let
Source = #table({"Firstname", "Surname", "Address 1", "Address 2"}, {{"data","data", "data", "data"}}),
ColumnToKeep = {"Firstname", "Surname"},
//ColumnNames = Table.ColumnNames(Source),
Custom1 = Table.SelectColumns(Source, ColumnToKeep)
in
Custom1
Thanks @latimeria - that is the idea however I would like to populate ColumnToKeep variable with rows from another table - is that possible? I guess if I convert rows to a list and insert to that variable?
Steve
Yes,
Table.ToColumns should be your friend
Excellent - thank you.
Final solution for reference.
let
Source = data,
GetColumnNames = Table.ToColumns(ColNames),
ColumnToKeep = GetColumnNames{0},
KeepCols = Table.SelectColumns(Source, ColumnToKeep)
in
KeepCols
Hi @StevenMorgan ,
If this can help:
let
Source = #table({"Firstname", "Surname", "Address 1", "Address 2"}, {{"data","data", "data", "data"}}),
ColumnToKeep = {"Firstname", "Surname"},
//ColumnNames = Table.ColumnNames(Source),
Custom1 = Table.SelectColumns(Source, ColumnToKeep)
in
Custom1
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
101 | |
52 | |
21 | |
12 | |
11 |