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
rmahmood
New Member

Expanding list within column

Hello,

I am having trouble trying to get a numerical list to expand or display from within a column in Power Query. 

I would appreciate any help!  List in Column.png

 

Please see attached picture.  Thank you!

1 ACCEPTED SOLUTION
edhans
Super User
Super User

Try this @rmahmood 
It uses Value.Is to determine if it is a list or not, then extracts the numbers. From there you can split columns, or whatever.

 

let
    Source = #table(
                {"ID", "Name", "City", "Other"},
                    {
                        {123, "Alice", "Wonderand", ""},
                        {456, "Bob", "Wonderland", {1..10}}
                    }
            ),
    #"Added Custom" = 
        Table.AddColumn(
            Source, 
            "Custom", 
            each 
                if Value.Is([Other], type list) 
                then Text.Combine(List.Transform([Other], Text.From), ",")
                else [Other]
        )
in
    #"Added Custom"

 

edhans_0-1627661353382.png

 

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

5 REPLIES 5
wdx223_Daniel
Super User
Super User

Table.SplitColumn(PreviousStepName,"Training Modules",each if _ is list then _ else {_},List.Max(List.Transform(PreviousStepName[Training Modules],each if _ is list then List.Count(_) else 1)))

mussaenda
Super User
Super User

Hi @rmahmood, Is this a custom column or coming from the source? 

Hi,

 

This is actually coming from the source.

edhans
Super User
Super User

Try this @rmahmood 
It uses Value.Is to determine if it is a list or not, then extracts the numbers. From there you can split columns, or whatever.

 

let
    Source = #table(
                {"ID", "Name", "City", "Other"},
                    {
                        {123, "Alice", "Wonderand", ""},
                        {456, "Bob", "Wonderland", {1..10}}
                    }
            ),
    #"Added Custom" = 
        Table.AddColumn(
            Source, 
            "Custom", 
            each 
                if Value.Is([Other], type list) 
                then Text.Combine(List.Transform([Other], Text.From), ",")
                else [Other]
        )
in
    #"Added Custom"

 

edhans_0-1627661353382.png

 

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Greg_Deckler
Super User
Super User

@rmahmood Seems like you are going to need an if statement to check if null, then return null or otherwise, extract values from the list like:

#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From)), type text})

 

Will be different if you are trying to expand to rows, would be:

#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")

 

@ImkeF and @edhans might have other thoughts.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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
Top Kudoed Authors