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
Anonymous
Not applicable

Split columns and sort outcome?

Hi all,

I'm trying to separate a column which has an array of key/values in it, and the keys are not always:

ColumnTags

{"App: App1","Build: Build1", "Environment: Dev","Run Time: 24x7"}

{"App: App2","Environment: QA", "Run Time: 24x7"}

{"Build: Build2","Run Time 24x7"}

 

First of all, when I split the columns by the comma, the first output creates only two columns, and selects the first two key/value pairs. Everything else gets deleted.

I have to specify the amount of columns I want to be certain no values are getting deleted.

Is this expected behaviour? Am I doing something wrong? Or is it a bug?

 

Second, and this makes sense, the columns are sequencial and are filled in the same order the array is listed, so if in the first column, the first row key/value is App, and in the second is Build, then it will look like this:

Column1Column2Column3Column4
App: App1Build: Build1Environment: DevRun Time: 24x7
App: App2Environment: QARun Time: 24x7$null
Build: Build2Run Time: 24x7$null$null

 

The $null values are expected and don't disrupt anything for me, but I do want to sort the values. For example, I want column 1 only to be App, and column 2 only be Build

Is this possible? How so?

 

 

Lastly, I want to know if there's any way to select only certain values from the array and use only those as columns? Say I want to use only App and Build and discard everything else. How can I do that?

Thanks in advance.

1 ACCEPTED SOLUTION
mwegener
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous 

 

first remove the curly braces

jsonLike_01.png

Add a Index (id)

jsonLike_02.png

Split Column by Comma into Rows (One Row for each Key:Value pair)

jsonLike_03.png

Split Column by Colon (Split Key:Value pair)

jsonLike_04.png

Pivot Column "Column1.1" -> Value Column "Column1.2" -> Don't Aggregate

jsonLike_05.png

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


View solution in original post

3 REPLIES 3
mwegener
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous,

 

try this:

 

let
Source = Table.FromColumns({Lines.FromBinary(File.Contents("C:\Test.txt"))}),
#"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1),
#"Extracted Text Between Delimiters" = Table.TransformColumns(#"Added Index", {{"Column1", each Text.BetweenDelimiters(_, "{", "}"), type text}}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Extracted Text Between Delimiters", {{"Column1", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1", type text}}),
#"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Column1.1", "Column1.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Column1.1", type text}, {"Column1.2", type text}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Column1.1]), "Column1.1", "Column1.2")
in
#"Pivoted Column"

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Anonymous
Not applicable

Thank you for the help.

Could you help me understand your Query so I know what to replace where and what am I doing?

Thanks again

mwegener
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous 

 

first remove the curly braces

jsonLike_01.png

Add a Index (id)

jsonLike_02.png

Split Column by Comma into Rows (One Row for each Key:Value pair)

jsonLike_03.png

Split Column by Colon (Split Key:Value pair)

jsonLike_04.png

Pivot Column "Column1.1" -> Value Column "Column1.2" -> Don't Aggregate

jsonLike_05.png

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Helpful resources

Announcements
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.