+ Reply to Thread
Results 1 to 5 of 5

Power Query extract values from list column with nulls

  1. #1
    Forum Contributor
    Join Date
    04-30-2010
    Location
    Denmark
    MS-Off Ver
    Office 365
    Posts
    215

    Power Query extract values from list column with nulls

    Hi all

    I have a list column, that includes nulls, like this:
    ExpandListWithNull1.png

    When I try to extract the values, I get errors on all the nulls:
    ExpandListWithNull2.png

    ExpandListWithNull3.png

    The code for this step is this:
    Please Login or Register  to view this content.
    I tried including something like this, in the step, but without success:
    Please Login or Register  to view this content.
    How can I avoid these errors when I extract values?

    PS: I would very much have liked to attach a sample sheet, but these list columns (I have a lot of them) are derived from a large dataset, which includes sensitive data, and Im not really sure how to make such a column from scratch.

    Best regards
    Imbizile

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,921

    Re: Power Query extract values from list column with nulls

    Have you tried replacing the nulls with something else before expanding the list?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Power Query extract values from list column with nulls

    Maybe try

    = Table.TransformColumns(#"Filtered Rows", {"departmentNumber", each if _ = null then null else Text.Combine(List.Transform(_, Text.From), ","), type text})

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Power Query extract values from list column with nulls

    There are multiple ways to deal with this sort of thing.

    If statement as Bo_Ry demonstrated.

    try ... otherwise statement.
    Please Login or Register  to view this content.
    Convert null into single item list before processing.

    etc.

    Edit: Which method to use, will largely depend on your data and processing need. List.Transform will throw error, when you are trying to transform non-list object. By using try... otherwise, it will handle all error cases. However, if you want to make sure only null is treated in this manner, it is better to use if statement to explicitly treat null values or apply type conversion before transformation. As try... otherwise will apply uniform error handling on all errors regardless of what caused the error.
    Last edited by CK76; 02-04-2021 at 07:32 AM.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  5. #5
    Forum Contributor
    Join Date
    04-30-2010
    Location
    Denmark
    MS-Off Ver
    Office 365
    Posts
    215

    Re: Power Query extract values from list column with nulls

    Perfect - Thanks a bunch for all your suggestions, they all work. I was not aware of the try otherwise function - that could be handy in other situations instead of if else.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Power Query Extract
    By AllisterB in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-17-2021, 05:49 PM
  2. [SOLVED] Power Query/Power Pivot Conditional Column creation & chart
    By mz_h in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-12-2020, 06:07 PM
  3. Replies: 8
    Last Post: 10-21-2020, 03:02 AM
  4. Extract data from Web using Power Query
    By jatin.c in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-23-2020, 08:38 AM
  5. Replies: 10
    Last Post: 06-25-2020, 12:19 AM
  6. [SOLVED] Power Pivot does not load new column added in Power query
    By ibuhary in forum Excel General
    Replies: 12
    Last Post: 02-19-2019, 03:53 AM
  7. Sub-Forum for Excel Power Tools (Power Query, Power Pivot & Power BI)
    By chullan88 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 06-28-2018, 02:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1