Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
StevenMorgan
Frequent Visitor

Include Columns from List/Table

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:

FirstnameSurnameAddress 1Address 2
datadatadatadata

 

Target columns:

Column NameKeep/Remove
FirstnameKeep
SurnameKeep
Address 1Remove
Address 2Remove

 

Target output:

FirstnameSurname
datadata

 

Any help appreciated.

 

Thanks,

 

Steve

1 ACCEPTED SOLUTION
latimeria
Solution Specialist
Solution Specialist

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

View solution in original post

4 REPLIES 4
StevenMorgan
Frequent Visitor

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
latimeria
Solution Specialist
Solution Specialist

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors