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
smpa01
Super User
Super User

Eliminate unwanted columns while connecting to Excel Workbook

Hi,

 

Is there a way to select only the columns I want while connecting to a Excel workbook. For eaxample, I am connecting to  a workbook that contains the following columns with the following code.

 

Batch NumberDoc TypeDocument NumberCompanyG/L DatePeriod NumberFiscal YearSupplier Name/ ExplanationAmountColumn1

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\smpa01\Desktop\Test.xlsx"), null, true),
    Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Batch Number", Int64.Type}, {"Doc Type", type text}, {"Document Number", Int64.Type}, {"Company", Int64.Type}, {"G/L Date", type date}, {"Period Number", Int64.Type}, {"Fiscal Year", Int64.Type}, {"Supplier Name/ Explanation", type text}, {"Amount", type number}, {"Column1", type text}})
in
    #"Changed Type"

If I only want Batch Number and Doc Type column is there a way to only select them in the following step.

Table1_Table

 Thank you in advance.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION

@v-piga-msft

 

I figured it out

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\smpa01\Desktop\Test.xlsx"), null, true),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "Sheet1")),
    #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Data"}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Removed Other Columns", "Data", {"Column1", "Column2"}, {"Data.Column1", "Data.Column2"}),
    #"Promoted Headers1" = Table.PromoteHeaders(#"Expanded Data", [PromoteAllScalars=true])
in
    #"Promoted Headers1"
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @smpa01,

 

If I understand your scenario correctly that you only want to keep Batch Number and Doc Type column when you connect excel workbook?

 

If it is, you could go to Query editor and Click Choose Columns, then you could select the columns you want to keep.

 

You also could refer to the expression highlight in red.

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\smpa01\Desktop\Test.xlsx"), null, true),
    Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Batch Number", Int64.Type}, {"Doc Type", type text}, {"Document Number", Int64.Type}, {"Company", Int64.Type}, {"G/L Date", type date}, {"Period Number", Int64.Type}, {"Fiscal Year", Int64.Type}, {"Supplier Name/ Explanation", type text}, {"Amount", type number}, {"Column1", type text}})
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"Batch Number", "Doc Type"})
in
#"Removed Other Columns"

 

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-piga-msft

 

I figured it out

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\smpa01\Desktop\Test.xlsx"), null, true),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "Sheet1")),
    #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Data"}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Removed Other Columns", "Data", {"Column1", "Column2"}, {"Data.Column1", "Data.Column2"}),
    #"Promoted Headers1" = Table.PromoteHeaders(#"Expanded Data", [PromoteAllScalars=true])
in
    #"Promoted Headers1"
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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.