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
Anonymous
Not applicable

How can I pivot a column base on a column with values and embedded lists?

I have a column with titles that I want to pivot, and the column with the cell info has both values and embeded lists.  I got this to work once, and now I can't repeat it.  I keep getting errors like "can't convert list to text".

 

Any ideas?

 

TitlesValues
NameElmer Fudd
Locations

List

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

this depends from whats in your List and how you would like to handle it. Here some basic examples

Transform the column content to list and expand afterwards the list to new rows

let
    Source = #table
    (
        type table [Titles=  any, Values=  any],
        {
            {"Name", "Elmer"}, {"Location", {"Street", "City"}}
        }
    ),
    Transform = Table.TransformColumns
    (
        Source,
        {
            {
                "Values",
                each if Value.Is(_,type list) then _ else {_},
                type list
            }
        }
    ),
    #"Expanded Values" = Table.ExpandListColumn(Transform, "Values")
in
    #"Expanded Values"

or you want to extract the first entry of your list like this

let
    Source = #table
    (
        type table [Titles=  any, Values=  any],
        {
            {"Name", "Elmer"}, {"Location", {"Street", "City"}}
        }
    ),
    Transform = Table.TransformColumns
    (
        Source,
        {
            {
                "Values",
                each if Value.Is(_,type list) then _{0} else _,
                type any
            }
        }
    )
in
    Transform

 

this to give you some ideas. If you have a more specific scenario, let me know

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

View solution in original post

1 REPLY 1
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

this depends from whats in your List and how you would like to handle it. Here some basic examples

Transform the column content to list and expand afterwards the list to new rows

let
    Source = #table
    (
        type table [Titles=  any, Values=  any],
        {
            {"Name", "Elmer"}, {"Location", {"Street", "City"}}
        }
    ),
    Transform = Table.TransformColumns
    (
        Source,
        {
            {
                "Values",
                each if Value.Is(_,type list) then _ else {_},
                type list
            }
        }
    ),
    #"Expanded Values" = Table.ExpandListColumn(Transform, "Values")
in
    #"Expanded Values"

or you want to extract the first entry of your list like this

let
    Source = #table
    (
        type table [Titles=  any, Values=  any],
        {
            {"Name", "Elmer"}, {"Location", {"Street", "City"}}
        }
    ),
    Transform = Table.TransformColumns
    (
        Source,
        {
            {
                "Values",
                each if Value.Is(_,type list) then _{0} else _,
                type any
            }
        }
    )
in
    Transform

 

this to give you some ideas. If you have a more specific scenario, let me know

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

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