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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
IanDavies
Helper III
Helper III

dealing with a list of records (and null values)

I am importing some data using an API, it comes as JSON and I can get the data I need from that until I get to the group(s) that each item is a member of.

 

each item can be a member of zero or more groups. if that number is zero it appears to enter a null value, for the others it has a record for each item with name & id.

 

this is what each list holds:

IanDavies_1-1728552766028.png

each record has two fields

IanDavies_2-1728552807277.png

except when its not in any groups and then it puts a null value in the row

IanDavies_3-1728552886123.png

when I try to expand that, either by using the GUI or a custom column it errors because it cant transform type null.
In other (similar) circumstances I would replace the null value, but I don't get that option.

Is there any method to expand this column (groups) to show its values without losing rows?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

On the contrary--if you extract to new rows, you will see that you still get only one row--a record, which was all that was in each list. Now you can extract the record values, instead of list items.

 

Just give it a try--it works.

 

--Nate

View solution in original post

14 REPLIES 14
Chewdata
Super User
Super User

hey,

Another possible solution is to create a new column that inserts a list with a default record in al the empty spaces. 

= Table.AddColumn(#"Replaced Value", "NewList", each [groups] ?? {[ID = 999999, Name = "Chewdata"]})

OR 
transform current column:
Table.ReplaceValue(#"Changed Type",null,[ID = 999999, Name = "Chewdata"],Replacer.ReplaceValue,{"groups"}

After that you can filter out the rows that have ID = 999999

Anonymous
Not applicable

On the contrary--if you extract to new rows, you will see that you still get only one row--a record, which was all that was in each list. Now you can extract the record values, instead of list items.

 

Just give it a try--it works.

 

--Nate

Ok, it works well enough for my purpose.

 

A word of warning to anybody who comes across this if the column has multiple records it will create multiple rows (1 per record)

in the screenshot the exaples are only in one group but there are some in multiple groups, I cant dispaly them  because it has the error and wont let me past row 86 (despite there being 1300 rows).

 

I'll try your method and see if I can demonstrate it.

like this:

Two records in the list

IanDavies_1-1728575203273.png


making two rows for this item:

IanDavies_0-1728574988413.png


Theer aren't many but it does happen.

Anonymous
Not applicable

On your Groups column, just click "Expand to New Rows" instead of "Extract Values".  This will expand yor lists to a single record per row.  After that, you can safely use the arrows at the top of the column to expand the values.

 

--Nate

This is an inventory, having multiple rows for the same item would be very difficut to manage unless there were a way to later merge them.

 

I cant think of one which is why I wasn't taking this option in the first place. 

 

I wish it would just ignore null values, if there is nothign there, there is nothing to expand/convert so why try?

Omid_Motamedise
Super User
Super User

Select that column, right click on it and pick replace command, then use the setting provided in the next image for replacing null values with a list.

 

Omid_Motamedise_0-1728555002918.png

 

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

tried that ... I noted this didnt work in my question:

IanDavies_0-1728557240322.png

 

this is what I get - note the lack of Replace Values

IanDavies_1-1728557305121.png

 

Perform the replace operation on a different column first. Then, go to the formula bar and update the formula by changing the column name in the fourth argument of Table.ReplaceValue to the desired column.

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
PhilipTreacy
Super User
Super User

@IanDavies 

 

Hi Ian,

 

I'm not 100% following you. When you refer to an item I don't know what that is.

 

You say each record has 2 fields except when its not in any groups and then it puts a null value in the row.

 

The image after this statement shows a column of Lists with a null value.  Where do the Records come in?

 

Is the issue that the groups column contains Lists or null values?  And each List contains a Record, which itself contains 2 values?

 

So what is the exact issue?  You want to get rid of the nulls in the groups column? 

 

You could create a Custom Column with this

 

 

if [groups] is null then "" else [groups]

 

 

then filter the blank values and extract your lists.

 

Or you could extract the lists and then remove rows with errors.

 

If that's not what you want please restate the issue clearly and show what you want as a final result.

 

Regards

 

Phil

 

 

 

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!



See reponse below in blue
@PhilipTreacy wrote:

@IanDavies 

 

Hi Ian,

 

I'm not 100% following you. When you refer to an item I don't know what that is.

each item = each row in the query.

 

You say each record has 2 fields except when its not in any groups and then it puts a null value in the row.

 

The image after this statement shows a column of Lists with a null value.  Where do the Records come in?

each list in [groups] has a record with two fields - see the additional screenshots in the original post

 

Is the issue that the groups column contains Lists or null values?  And each List contains a Record, which itself contains 2 values?

yes

 

So what is the exact issue?  You want to get rid of the nulls in the groups column? 

I want to be able to convert the lists to data that can be read but that fails because of the null values. I would normally replace the null values but I can't do that in the GUI

 

You could create a Custom Column with this

 

if [groups] is null then "" else [groups]

 

So I did this and it has created a new column

 

then filter the blank values and extract your lists.

The filter only has Select all or Blanks

IanDavies_2-1728558177838.png 

Also I cant expand the new custom column

IanDavies_6-1728558789984.png

 

Or you could extract the lists and then remove rows with errors.

not sure what you mean by "extract the lists"

 

If that's not what you want please restate the issue clearly and show what you want as a final result.

 

I want this but without errors - two columns with the values from the list/records of the [groups] column

IanDavies_3-1728558400076.png

I created this example by creatng a custom column using Table.FromRecords([groups]) then expanding the custom column, but when I do this I get an error appear in EVERY column at the bottom of the previewed data, which isnt there in previous steps

 

IanDavies_4-1728558587240.png

 

Is this clearer?

 

Ian

 

 


 

 

 

 

Hi @IanDavies 

 

Download PBIX file with examples below

 

The file I created shows both examples I described.

 

If you Extract Values

 

PhilipTreacy_0-1728606240381.png

 

you get Errors where there were nulls

 

PhilipTreacy_2-1728606343824.png

 

You can then right click the column header and Replace Errors with nothing (blanks)

 

PhilipTreacy_3-1728606390486.png

 

then filter out blanks

 

 

The other way is to create a Custom Column with this

 

 

= if [groups] is null then "" else [groups]

 

 

 

PhilipTreacy_4-1728606481372.png

 

You can then Remove Empty cells (my bad - I wrote filter blanks earlier)

 

PhilipTreacy_5-1728606509033.png

 

This leaves you with just Lists which can be expanded

 

PhilipTreacy_6-1728606572801.png

 

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thank you your time, I wont have a chance to loo at this again until next week but I will look at both solutions. My concern with them both is that I will lose rows of data simply because they arent a member of a group, which is something I need to count\highlight in my dashboard.

I tried an amended version of your if statement but got a different error entirely:

 

= if [groups] is null then List.Generate(() => [ name = "none", id = 0],each [id] = 0,each [id = [id] + 1])else [groups]

 

 This was an attenpt to add a list with one record in it that had the same fields as those imported. It appeared to work and if you look at the previously null records they do now have a list with one record in them but I am now  getting this error:

IanDavies_0-1728633439030.png


I'll have a look at your suggestions and see whether they work or not.



Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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