cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gaby_Scarcella
New Member

How to use a list of values from Excel cell in Csv.Document function?

Hi all!

 

In order to parse fixed-width files with variable number of characters that marks the start of each column, I'd like to use a list of values stored in a cell in an Excel document. To do so, I retrieved the values from the cell and converted it in a list of values, like this:

ColumnsFromExcel = Excel.CurrentWorkbook(){[Name="ColumnasSeparadorasRCV"]}[Content]{0}[Column1],

#"ColumnsList (text)" = Text.Split(ColumnsFromExcel, ", "),

#"ColumnsList (num)" = List.Transform(#"ColumnsList (text)", each Number.FromText(_)),

 

When I try to use the resulting list from Excel cell, Csv.Document function returns just one column, however, if using a typed list of values, the function returns the expected number of columns. Both lists seems to be identical:

Crop_CaracteresDesdeInicio.jpg

Crop_ColumnsList (num).jpg

 

I couldn't find a solution for this so far. Any help would be appreciated!

1 ACCEPTED SOLUTION

Thanks. This makes it clear exactly what's going on.

 

In your first line, it's interpreting "ColumnsList (num)" as a literal string rather than a reference to a list. In order to disambiguate, try it with an octothorpe (#) in front.

Source = Csv.Document(File.Contents(FilePath & FileName),null,#"ColumnsList (num)",null,1252),

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

When I try to use the resulting list from Excel cell, Csv.Document function returns just one column

I'm not following how exactly you're using the lists. Can you share the code for the step with the Csv function?

Hi @AlexisOlson.
Thanks for the fast reply.

I'm trying to use this code:
Source = Csv.Document(File.Contents(FilePath & FileName),null,"ColumnsList (num)", null,1252),


instead of:


Source = Csv.Document(File.Contents(FilePath & FileName),null,{0, 9, 28, 36, 40, 45, 55, 65, 71},null,1252),

Thanks. This makes it clear exactly what's going on.

 

In your first line, it's interpreting "ColumnsList (num)" as a literal string rather than a reference to a list. In order to disambiguate, try it with an octothorpe (#) in front.

Source = Csv.Document(File.Contents(FilePath & FileName),null,#"ColumnsList (num)",null,1252),

That did the trick, thank you @AlexisOlson for pointing the error in my code.

Really appreciate your help.

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors