Search code examples
excelpowerquerym

Power Query only load first 20 columns


My current code

let
Filepath = Excel.CurrentWorkbook(){[Name="Filepath"]}[Content]{0}[Column1],
Subpath = Excel.CurrentWorkbook(){[Name="path_2.3"]}[Content]{0}[Column2],
Mappe = Excel.CurrentWorkbook(){[Name="path_2.3"]}[Content]{0}[Column3],
Path = Folder.Files(Filepath&Subpath),
File = Path [Name]{0},
Source = Excel.Workbook(File.Contents(Filepath&Subpath&File), null, true),
Import = Source{[Item=Mappe,Kind="Sheet"]}[Data]
in
Import

Issue: The Sheet the code loads is messy and I can not change it (company stuff reasons). The sheet contains millions of blank columns which inflates the resulting table into many MB big.

Import = Source{[Item=Mappe,Kind="Sheet"]}[Data] loads all data.

What I need: A code to dynamicly load only the first 20 columns.


Solution

  • Add a new step like this:

    = Table.SelectColumns(Import, List.FirstN(Table.ColumnNames(Import), 20))