Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to convert a column in PowerBI

I have some data from a data source (which I can’t influence) which I’ve imported into PowerBI (using "Import"), and one column in particular (answers to questions) returns varying data – sometimes it’s a JSON array with three options, but sometimes it’s also data directly.

Example:

Answer
-----------------------------
["German","English","French"]
["Ja","Yes","Oui"]
0
1
3006
Bern

I would like to "convert" this mixed bag of data so that

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • if it really is a JSON array, I want to take the first value (always)
  • if it is NOT a JSON array, I just want to take the data unchanged

So in the end, I’d like to have this:

Answer
------
German
Ja
0
1
3006
Bern

But somehow, I just can’t seem to get the hang of it. How can I "conditionally" pick the first value from a JSON array or just copy the data (if it’s not a JSON array)? Any ideas? I’m still trying to get the hang of doing stuff in PowerBI ….

>Solution :

Add a new custom column with:

try Json.Document([Answer]){0} otherwise [Answer]

enter image description here

Or, if you want to update the same column:

= Table.TransformColumns(#"Previous Step", {"Answer", each try Json.Document(_){0} otherwise _})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading