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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
James_SR
New Member

Error with JSON - Error with Record.List - Cannot convert the value to type List

Hi all,

 

I'm reasonably new to Power BI so this might be an easy one.

 

I'm trying to extract some nested JSON data.  The information is contained, currently, as a long list of values, three for each item - area 1 has total population, female population then male population.  Then we move in to area 2 - total, female, male and so on.  It looks when expanded similar to this - this is the data for first area:

 

Area / values.values
Record / 5033
Record / 2628
Record / 2405

Or view this image.

 

The Dax I have so far is as follows:

let
    Source = Json.Document(Web.Contents("http://webservices.esd.org.uk/data?value.valueType=raw&metricType=XXX")),
    rows = Source[rows],
    #"Converted to Table" = Table.FromList(rows, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"area", "values"}, {"area", "values"}),
    Expand= Table.ExpandListColumn(#"Expanded Column1", "values"),
    // The JSON array is expanded here with Record.FromList    
    Custom = Table.AddColumn(Expand, "Custom", each Record.FromList([values][value], type [Total=number, Males=number, Females=number]))
in
    Custom

Up until the addition of the custom column in the last couple of rows, it works fine.  However, the Custom column with the Record.FromList fails with the error message:

 

Expression.Error: We cannot convert the value 2628 to type List.
Details:
    Value=2628
    Type=Type

 

A copy of the data is available.  Having searched online, this website shows a similar nested structure and uses Record.List.  I've also explored the Power BI community forum, including these two about nested JSON, but these don't appear to address the same issue.

 

Can anyone shed any light on this please? 

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

you can find some further concepts on how to handle JSON in Power Query here: https://www.thebiccountant.com/tag/json/

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
ImkeF
Community Champion
Community Champion

Hi @James_SR ,

I'd parse out your sample data like so:

 

let
    Source = Json.Document(Web.Contents("https://raw.githubusercontent.com/James-SR/Files/master/nesteddata.json")),
    rows = Source[rows],
    #"Converted to Table" = Table.FromList(rows, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"area", "values"}, {"area", "values"}),
    #"Expanded area" = Table.ExpandRecordColumn(#"Expanded Column1", "area", {"identifier", "label", "altLabel", "isSummary"}, {"identifier", "label", "altLabel", "isSummary"}),
    #"Expanded values" = Table.ExpandListColumn(#"Expanded area", "values"),
    #"Expanded values1" = Table.ExpandRecordColumn(#"Expanded values", "values", {"source", "value", "formatted", "format", "publicationStatus"}, {"source", "value", "formatted", "format", "publicationStatus"})
in
    #"Expanded values1"

 

Hope it hold the structure you need for your actual data. Otherwise please post sample data that matches your structure.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Community Champion
Community Champion

you can find some further concepts on how to handle JSON in Power Query here: https://www.thebiccountant.com/tag/json/

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thanks @ImkeF - that is a step closer.

 

I presume then the best next step will be to create an index, then pivot on this index?

The answer is in this post:

 

https://www.thebiccountant.com/2017/08/30/how-to-open-a-complex-json-record-in-power-bi-and-power-qu...

 

Using the code:

 

Table.FromRecords( { MyJsonRecord } )

For example:

 

let
    MyJsonRecord = Json.Document(Web.Contents("http://api.tvmaze.com/singlesearch/shows?q=house-of-cards&embed=episodes")),
    MyJsonTable= Table.FromRecords( { MyJsonRecord } )
in
    MyJsonTable

Thank you to @ImkeF for the answer

 

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.