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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
dirkhiggler
New Member

Cannot convert value "0" to type table

Hi all,

 

I've searched high and low but haven't been able to find a solution to my exact problem, which is similar to a number of other posts, but not the same from what I can see.

 

I'm pulling data from an internal PostgresSQL server, which contains 2 fields, one is an integer "record_id", the other is JSONB data "data". The JSONB field contains valid JSON objects, including multiple nested JSON objects.

 

PBI is able to parsed the JSON, allowing me to expand almost all the nested data into columns. On two of the nested columns however, it fails with the "Cannot convert value "0" to type table" error.

 

Below is the query. If I remove the last step "#Expanded defect_2", the error disappears. But I need to be able to access data within 'defect_2'. In the source database, defect_2 contains a mixture of "null" and JSON data (it's a non-compulsory field). I've tried all different things, including replacing null with 0, which removes the ability to expand the column, tried transforming the columns data type, etc.

 

let
    Source = PostgreSQL.Database("syd-pg-01.csn2swo3zzki.ap-southeast-2.rds.amazonaws.com", "mgpg"),
    iform_mg_qa_product = Source{[Schema="iform",Item="mg_qa_product"]}[Data],
    #"Parsed JSON" = Table.TransformColumns(iform_mg_qa_product,{{"data", Json.Document}}),
    #"Expanded data" = Table.ExpandRecordColumn(#"Parsed JSON", "data", {"record"}, {"record"}),
    #"Expanded record" = Table.ExpandRecordColumn(#"Expanded data", "record", {"dest", "house", "signed", "quantity", "supplier", "container", "line_text", "CREATED_BY", "description", "line_number", "CREATED_DATE", "product_code", "product_type", "qr_code_scan", "MODIFIED_DATE", "product_count", "product_weight", "text_from_scan", "assessment_line", "supplier_ref_no", "assessment_line1", "container_qrcode", "person_completing_qa", "please_complete_product_check", "text_from_container_report_scan"}, {"dest", "house", "signed", "quantity", "supplier", "container", "line_text", "CREATED_BY", "description", "line_number", "CREATED_DATE", "product_code", "product_type", "qr_code_scan", "MODIFIED_DATE", "product_count", "product_weight", "text_from_scan", "assessment_line", "supplier_ref_no", "assessment_line1", "container_qrcode", "person_completing_qa", "please_complete_product_check", "text_from_container_report_scan"}),
    #"Expanded please_complete_product_check" = Table.ExpandListColumn(#"Expanded record", "please_complete_product_check"),
    #"Expanded please_complete_product_check1" = Table.ExpandRecordColumn(#"Expanded please_complete_product_check", "please_complete_product_check", {"record"}, {"record"}),
    #"Expanded record1" = Table.ExpandRecordColumn(#"Expanded please_complete_product_check1", "record", {"sizes", "photo_1", "photo_2", "product", "comments", "defect_2", "defect_3", "firmness", "temp_rec", "container", "appearance", "fumigation", "shelf_life", "defect_2_pc", "defect_3_pc", "nett_weight", "rots_moulds", "sample_size", "carton_photo", "count_numbers", "defect_2_type", "defect_3_type", "maturity_brix", "defect_2_total", "defect_3_total", "eating_quality", "rots_moulds_pc", "colour_external", "colour_internal", "defect_comments", "grower_lot_code", "pulp_temp_lowest", "pulp_temp_highest", "rots_moulds_total", "appearance_comment", "shelf_life_comment", "sizing_discrepancy", "marketability_score", "newest_packed_on_date", "oldest_packed_on_date", "packed_on_date_exists", "eating_quality_comment", "temperature_related_issue", "further_inspection_required", "additional_photos_if_required", "quality_characteristics_comments"}, {"sizes", "photo_1", "photo_2", "product", "comments", "defect_2", "defect_3", "firmness", "temp_rec", "container.1", "appearance", "fumigation", "shelf_life", "defect_2_pc", "defect_3_pc", "nett_weight", "rots_moulds", "sample_size", "carton_photo", "count_numbers", "defect_2_type", "defect_3_type", "maturity_brix", "defect_2_total", "defect_3_total", "eating_quality", "rots_moulds_pc", "colour_external", "colour_internal", "defect_comments", "grower_lot_code", "pulp_temp_lowest", "pulp_temp_highest", "rots_moulds_total", "appearance_comment", "shelf_life_comment", "sizing_discrepancy", "marketability_score", "newest_packed_on_date", "oldest_packed_on_date", "packed_on_date_exists", "eating_quality_comment", "temperature_related_issue", "further_inspection_required", "additional_photos_if_required", "quality_characteristics_comments"}),
    #"Expanded defect_3" = Table.ExpandListColumn(#"Expanded record1", "defect_3"),
    #"Expanded defect_1" = Table.ExpandRecordColumn(#"Expanded defect_3", "defect_3", {"record"}, {"defect_3.record"}),
    #"Expanded defect_3.record" = Table.ExpandRecordColumn(#"Expanded defect_1", "defect_3.record", {"defect_count"}, {"defect_3.record.defect_count"}),
    #"Expanded additional_photos_if_required" = Table.ExpandListColumn(#"Expanded defect_3.record", "additional_photos_if_required"),
    #"Expanded additional_photos_if_required1" = Table.ExpandRecordColumn(#"Expanded additional_photos_if_required", "additional_photos_if_required", {"record"}, {"additional_photos_if_required.record"}),
    #"Expanded additional_photos_if_required.record" = Table.ExpandRecordColumn(#"Expanded additional_photos_if_required1", "additional_photos_if_required.record", {"photo"}, {"additional_photos_if_required.record.photo"}),
    #"Expanded defect_2" = Table.ExpandListColumn(#"Expanded additional_photos_if_required.record", "defect_2")
in
    #"Expanded defect_2"

As I've been able to expand many other nested objects, I'm guessing the issue is somehow related to the data, but I don't understand where the 0 is coming from. After this step I would expect to ExpandRecordColumn on the result, then again to access the nested data I need.

 

First time posting so apologies if this is too much / not enough infomation.

 

Regards

Iain

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@dirkhiggler,

 

You may try to change it as follows.

    #"Expanded defect_2" = Table.ExpandListColumn(Table.ReplaceValue(#"Expanded additional_photos_if_required.record"
                                                                    , each [defect_2]
                                                                    , each if Value.Is([defect_2], type list) then [defect_2] else {}
                                                                    , Replacer.ReplaceValue
                                                                    , {"defect_2"})
                                                , "defect_2")
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@dirkhiggler,

 

You may try to change it as follows.

    #"Expanded defect_2" = Table.ExpandListColumn(Table.ReplaceValue(#"Expanded additional_photos_if_required.record"
                                                                    , each [defect_2]
                                                                    , each if Value.Is([defect_2], type list) then [defect_2] else {}
                                                                    , Replacer.ReplaceValue
                                                                    , {"defect_2"})
                                                , "defect_2")
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi v-chuncz-msft,

 

Thanks very much for your help, that has solved the problem very elegantly.

 

Regards,
Iain

dirkhiggler
New Member

Hi all,

 

I have searched for days trying to find a solution to this problem, but none of the posts I find match my issue exactly.

 

I'm reporting from an internal PostgreSQL database, which contains JSONB columns. The JSONB columns contain JSON objects with multiple nested JSON objects going down a few layers.

 

PBI is able to parse the JSON, and allows me to expand to new rows most of the JSON records. However, when I try to expand on some of the columns, I get the specific Cannot convert the value "0" to type Table error.

 

As you can see from the query, I've been able to parse the JSON, and expand records and lists to expose the data I need for a number of the columns. However, the last line "Expanded_defect_2" causes the error. I'm assuming that it's possibly data related - some of the defect_2 records are null, the rest contain valid JSON. Other columns I've been able to successfully expand also contain a mixture of null and actual data.

 

let
    Source = PostgreSQL.Database("XYZ.com", "mgpg"),
    iform_mg_qa_product = Source{[Schema="iform",Item="mg_qa_product"]}[Data],
    #"Parsed JSON" = Table.TransformColumns(iform_mg_qa_product,{{"data", Json.Document}}),
    #"Expanded data" = Table.ExpandRecordColumn(#"Parsed JSON", "data", {"record"}, {"record"}),
    #"Expanded record" = Table.ExpandRecordColumn(#"Expanded data", "record", {"dest", "house", "signed", "quantity", "supplier", "container", "line_text", "CREATED_BY", "description", "line_number", "CREATED_DATE", "product_code", "product_type", "qr_code_scan", "MODIFIED_DATE", "product_count", "product_weight", "text_from_scan", "assessment_line", "supplier_ref_no", "assessment_line1", "container_qrcode", "person_completing_qa", "please_complete_product_check", "text_from_container_report_scan"}, {"dest", "house", "signed", "quantity", "supplier", "container", "line_text", "CREATED_BY", "description", "line_number", "CREATED_DATE", "product_code", "product_type", "qr_code_scan", "MODIFIED_DATE", "product_count", "product_weight", "text_from_scan", "assessment_line", "supplier_ref_no", "assessment_line1", "container_qrcode", "person_completing_qa", "please_complete_product_check", "text_from_container_report_scan"}),
    #"Expanded please_complete_product_check" = Table.ExpandListColumn(#"Expanded record", "please_complete_product_check"),
    #"Expanded please_complete_product_check1" = Table.ExpandRecordColumn(#"Expanded please_complete_product_check", "please_complete_product_check", {"record"}, {"record"}),
    #"Expanded record1" = Table.ExpandRecordColumn(#"Expanded please_complete_product_check1", "record", {"sizes", "photo_1", "photo_2", "product", "comments", "defect_2", "defect_3", "firmness", "temp_rec", "container", "appearance", "fumigation", "shelf_life", "defect_2_pc", "defect_3_pc", "nett_weight", "rots_moulds", "sample_size", "carton_photo", "count_numbers", "defect_2_type", "defect_3_type", "maturity_brix", "defect_2_total", "defect_3_total", "eating_quality", "rots_moulds_pc", "colour_external", "colour_internal", "defect_comments", "grower_lot_code", "pulp_temp_lowest", "pulp_temp_highest", "rots_moulds_total", "appearance_comment", "shelf_life_comment", "sizing_discrepancy", "marketability_score", "newest_packed_on_date", "oldest_packed_on_date", "packed_on_date_exists", "eating_quality_comment", "temperature_related_issue", "further_inspection_required", "additional_photos_if_required", "quality_characteristics_comments"}, {"sizes", "photo_1", "photo_2", "product", "comments", "defect_2", "defect_3", "firmness", "temp_rec", "container.1", "appearance", "fumigation", "shelf_life", "defect_2_pc", "defect_3_pc", "nett_weight", "rots_moulds", "sample_size", "carton_photo", "count_numbers", "defect_2_type", "defect_3_type", "maturity_brix", "defect_2_total", "defect_3_total", "eating_quality", "rots_moulds_pc", "colour_external", "colour_internal", "defect_comments", "grower_lot_code", "pulp_temp_lowest", "pulp_temp_highest", "rots_moulds_total", "appearance_comment", "shelf_life_comment", "sizing_discrepancy", "marketability_score", "newest_packed_on_date", "oldest_packed_on_date", "packed_on_date_exists", "eating_quality_comment", "temperature_related_issue", "further_inspection_required", "additional_photos_if_required", "quality_characteristics_comments"}),
    #"Expanded defect_3" = Table.ExpandListColumn(#"Expanded record1", "defect_3"),
    #"Expanded defect_1" = Table.ExpandRecordColumn(#"Expanded defect_3", "defect_3", {"record"}, {"defect_3.record"}),
    #"Expanded defect_3.record" = Table.ExpandRecordColumn(#"Expanded defect_1", "defect_3.record", {"defect_count"}, {"defect_3.record.defect_count"}),
    #"Expanded additional_photos_if_required" = Table.ExpandListColumn(#"Expanded defect_3.record", "additional_photos_if_required"),
    #"Expanded additional_photos_if_required1" = Table.ExpandRecordColumn(#"Expanded additional_photos_if_required", "additional_photos_if_required", {"record"}, {"additional_photos_if_required.record"}),
    #"Expanded additional_photos_if_required.record" = Table.ExpandRecordColumn(#"Expanded additional_photos_if_required1", "additional_photos_if_required.record", {"photo"}, {"additional_photos_if_required.record.photo"}),
    #"Expanded defect_2" = Table.ExpandListColumn(#"Expanded additional_photos_if_required.record", "defect_2")
in
    #"Expanded defect_2"

I've tried replacing the null values and transforming the data type among other things, all to no avail.

 

Can anyone provide any suggestions on what I need to look for here?

 

Any help is much, much appreciated.

 

Regards,

Iain

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.