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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

List columns simultaneous expansion

Hello Community,

 

First of all, I hope all of and your families are safe during this period.

 

I would appreciated it if you could help me with the below task.

 

I have a table that includes two list columns.

 

GeorgeGiannakis_0-1602071516774.png

 

After expanding the Lists, I get the below result.

 

GeorgeGiannakis_1-1602071534657.png

 

I want to expand the "Year" column and then, to expand the "Count" column in such a way that it will result in something like the below table (the "Count" column will include the correct value per "Year" per "Ref").

 

GeorgeGiannakis_3-1602071721271.png

 

Any help would be hugely appreciated.

 

Kind regards,

 

George

 

 

 

 

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

check out this solution. It adds a new column to your data, creating a table out of your year and count column. After that the list-columns are deleted and the new table expanded

let
    Source = #table({"Ref", "Year", "Count"}, {{"181", {"2019", "2020"}, {"50000", "34000"}},{"182", {"2019", "2020"}, {"50000000", "34000000"}}}),
    AddTable = Table.AddColumn
    (
        Source,
        "TableYearCount",
        each Table.FromColumns({_[Year], _[Count]}, {"Year","Count"}),
        type table
    ),
    RemoveYearCount = Table.RemoveColumns(AddTable,{"Year", "Count"}),
    ExpandYearCount = Table.ExpandTableColumn(RemoveYearCount, "TableYearCount", {"Year", "Count"}, {"Year", "Count"})
in
    ExpandYearCount

Jimmy801_0-1602074861346.png

 

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

4 REPLIES 4
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

check out this solution. It adds a new column to your data, creating a table out of your year and count column. After that the list-columns are deleted and the new table expanded

let
    Source = #table({"Ref", "Year", "Count"}, {{"181", {"2019", "2020"}, {"50000", "34000"}},{"182", {"2019", "2020"}, {"50000000", "34000000"}}}),
    AddTable = Table.AddColumn
    (
        Source,
        "TableYearCount",
        each Table.FromColumns({_[Year], _[Count]}, {"Year","Count"}),
        type table
    ),
    RemoveYearCount = Table.RemoveColumns(AddTable,{"Year", "Count"}),
    ExpandYearCount = Table.ExpandTableColumn(RemoveYearCount, "TableYearCount", {"Year", "Count"}, {"Year", "Count"})
in
    ExpandYearCount

Jimmy801_0-1602074861346.png

 

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

 

 

 

Anonymous
Not applicable

Thank you Jimmy,

 

This worked just fine!!!

 

The code I used is 

 

= Table.AddColumn(#"Renamed Columns", "TableYearCount",each Table.FromColumns({_[Year],_[Count]},{"Year","Count"}),type table)

 

, where #"Renamed Columns" is the previous applied step.

 

It also took me a while to figure out that in order for this to work, the lists must not be expanded.

 

Kind regards,

 

George

Fowmy
Super User
Super User

@Anonymous 

Can you share the source data you used in the screenshot?

You can save your files in OneDrive, Google Drive, or any other cloud sharing platforms and share the link here.
____________________________________
How to paste sample data with your question?
How to get your questions answered quickly?

_____________________________________
Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Hello Fowmy,

 

Please see below.

https://1drv.ms/x/s!Av7SCtwcEG01lDA24NLYjLOY91Ne?e=XVyz8g

 

IdYearCount

1812019:202050000:34000
1822019:20201000000:2500000
2052020:2020350000:435000
2642019:202055000:220000
3822019:202015000:185000
4062021:2022:2023:2024 141252: 306251: 306251: 306251
5592021:2022:202390000:148000:187000

 

Thank you,

George

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors