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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Moomins
Regular Visitor

Query to combine 1st Column & Last 32 Columns

Hi

 

I have a table with over 1500 columns. 

The 1st column "Name" and the remaining columns are dates going back to 2017, dates are added to everyday.

So I'd like a Query that will combine 1st Column "Name" & Last 32 Columns. 

 

Below is my query and I stumble at the last after LastNCol. LastNCol successfully lists the 32 columns I want but when I then want to combine these with "Name" I get an error

 

Much appreciated any help to point me in the right direction.

TY

 

let
Source = Excel.Workbook(File.Contents("C:\Users\PC\Desktop\HL Fund Prices1.xlsx"), null, true),
Prices_Sheet = Source{[Item="Prices",Kind="Sheet"]}[Data],
#"Removed Top Rows" = Table.Skip(Prices_Sheet,2),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
#"Removed Columns" = Table.RemoveColumns(#"Promoted Headers",{"Day #(lf)%chg", "Day RANK", "30days", "30day RANK", "10days", "10days RANK", "5days", "5days RANK", "3days", "3days RANK", "AVG", "% Diff to MAX", "MAX", "Days since LARGE", "DAYS", "TRUE", "Column1619", "10 days", "5 days", "30 days"}),
LastNCol = List.LastN(Table.ColumnNames(#"Removed Columns"),32),#"Removed Other Columns" = Table.SelectColumns(#"Removed Columns",{"Name"} & {LastNCol})
in
#"Removed Other Columns"

1 ACCEPTED SOLUTION

the limit is actually 16000

 

let
  Source = Excel.Workbook(File.Contents("C:\Users\PC\Desktop\HL Fund Prices1.xlsx"), null, true), 
  Prices_Sheet = Source{[Item = "Prices", Kind = "Sheet"]}[Data], 
  #"Removed Top Rows" = Table.Skip(Prices_Sheet, 2), 
  #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars = true]), 
  FirstNCol = List.FirstN(Table.ColumnNames(#"Promoted Headers"), 1), 
  LastNCol = List.LastN(Table.ColumnNames(#"Promoted Headers"), 32), 
  #"Removed Other Columns" = Table.SelectColumns(#"Removed Columns", FirstNCol & LastNCol)
in
  #"Removed Other Columns"

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

1500 columns? What could possibly go wrong?   Extra points if you know the column limit in Power BI.

 

What's the error message? Is [Name] always the first column?

let
  Source = Excel.Workbook(File.Contents("C:\Users\PC\Desktop\HL Fund Prices1.xlsx"), null, true), 
  Prices_Sheet = Source{[Item = "Prices", Kind = "Sheet"]}[Data], 
  #"Removed Top Rows" = Table.Skip(Prices_Sheet, 2), 
  #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars = true]), 
  LastNCol = List.LastN(Table.ColumnNames(#"Promoted Headers"), 32), 
  #"Removed Other Columns" = Table.SelectColumns(#"Removed Columns", {"Name"} & {LastNCol})
in
  #"Removed Other Columns"

 

 

 

Hi @lbendlin 

 

1500+ columns guessing it's exceedng the column limit in Power BI (EEEEK!) Is Power BI same as Power Query?

Yes, Name always the 1st column

 

Error is -

Expression.Error: We cannot convert a value of type List to type Text.
Details:
Value=[List]
Type=[Type]

 

Thanks for looking into this for me!

the limit is actually 16000

 

let
  Source = Excel.Workbook(File.Contents("C:\Users\PC\Desktop\HL Fund Prices1.xlsx"), null, true), 
  Prices_Sheet = Source{[Item = "Prices", Kind = "Sheet"]}[Data], 
  #"Removed Top Rows" = Table.Skip(Prices_Sheet, 2), 
  #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars = true]), 
  FirstNCol = List.FirstN(Table.ColumnNames(#"Promoted Headers"), 1), 
  LastNCol = List.LastN(Table.ColumnNames(#"Promoted Headers"), 32), 
  #"Removed Other Columns" = Table.SelectColumns(#"Removed Columns", FirstNCol & LastNCol)
in
  #"Removed Other Columns"

Thank you so much @lbendlin !! I appreciated your help.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors