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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Split column into several columns per number of interview score

Hi community,

I've got th following column which I'd like to split so as to separate the interview scores (one interview score per column)  

Fizzy_Mojito_0-1639237537782.png

 

Desired outcome

 

Interview Score 1Interview Score 1Interview Score 1Interview Score 1Interview Score 1
33+2.53.53

 

Here's the full list of all possible interview scores

Fizzy_Mojito_1-1639237729299.png

 

Thank you for your help

Giac

 

1 ACCEPTED SOLUTION
Thingsclump
Resolver V
Resolver V

Hi @Anonymous 

 

Below is the solution. Copy the code at the end and it should work. Only exception is that you can not have same column name multiple times in PQ. In your desired outcome, "Interview Score 1" column is repeated mutlple times and its not allowed in PQ.

 

Input.

Thingsclump_0-1639243673253.png

 

 

Result

Thingsclump_1-1639243692105.png

 

 

Code:

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQrKL81LUTC0UjDWVoCwjZDYxkC2nqlSrE60khOKYiS1YFlnFFml2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Candidate = _t, #"Interview score" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Candidate", type text}, {"Interview score", type text}}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Interview score", Splitter.SplitTextByDelimiter("Round", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Interview score"),
#"Filtered Rows" = Table.SelectRows(#"Split Column by Delimiter", each ([Interview score] <> "")),
#"Replaced Value" = Table.ReplaceValue(#"Filtered Rows"," ","",Replacer.ReplaceText,{"Interview score"}),
#"Split Column by Delimiter1" = Table.SplitColumn(#"Replaced Value", "Interview score", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Interview score.1", "Interview score.2"}),
#"Renamed Columns" = Table.RenameColumns(#"Split Column by Delimiter1",{{"Interview score.1", "Interview score"}}),
#"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", each "Interview score " & [Interview score]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Interview score"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom]), "Custom", "Interview score.2")
in
#"Pivoted Column"

 

Accpet it as a solution if it answers your question!

 

Thanks

thingsclump

www.thingsclump.com 

 

View solution in original post

5 REPLIES 5
Thingsclump
Resolver V
Resolver V

Hi @Anonymous 

 

Below is the solution. Copy the code at the end and it should work. Only exception is that you can not have same column name multiple times in PQ. In your desired outcome, "Interview Score 1" column is repeated mutlple times and its not allowed in PQ.

 

Input.

Thingsclump_0-1639243673253.png

 

 

Result

Thingsclump_1-1639243692105.png

 

 

Code:

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQrKL81LUTC0UjDWVoCwjZDYxkC2nqlSrE60khOKYiS1YFlnFFml2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Candidate = _t, #"Interview score" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Candidate", type text}, {"Interview score", type text}}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Interview score", Splitter.SplitTextByDelimiter("Round", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Interview score"),
#"Filtered Rows" = Table.SelectRows(#"Split Column by Delimiter", each ([Interview score] <> "")),
#"Replaced Value" = Table.ReplaceValue(#"Filtered Rows"," ","",Replacer.ReplaceText,{"Interview score"}),
#"Split Column by Delimiter1" = Table.SplitColumn(#"Replaced Value", "Interview score", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Interview score.1", "Interview score.2"}),
#"Renamed Columns" = Table.RenameColumns(#"Split Column by Delimiter1",{{"Interview score.1", "Interview score"}}),
#"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", each "Interview score " & [Interview score]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Interview score"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom]), "Custom", "Interview score.2")
in
#"Pivoted Column"

 

Accpet it as a solution if it answers your question!

 

Thanks

thingsclump

www.thingsclump.com 

 

Anonymous
Not applicable

This is brilliant! Thank you, @Thingsclump 

I've noticed that I get what appears to be duplicates. I think this may be because there's a space after the numbers. Any idea on how to bulk replace them  

Fizzy_Mojito_0-1639303259482.png

 

Ideally, I'd like to get to the following conversion

Fizzy_Mojito_1-1639303401168.png

 

Hi @Anonymous 

 

You can select values column and replace " " (space) with nothing. It should work.

 

Thingsclump_0-1639305417356.png

 

For conversion, you can add a conditional column as below before pivoting step and use it.

 

Thingsclump_0-1639305729466.png

 

Thank you.

Anonymous
Not applicable

I tried removing " " (space) as per your suggestion but it didn't work so maybe it's not a space? What I've also found out is that there appears to be duplicates in Power Query, but when I apply the changes and open Power BI in table view the duplicates don't appear to be there anymore. Perhaps I would convert the interview scores using DAX instead of M?

The desired end result is the average of all scores, hence why I need to convert them.

@Anonymous 

Select the numbers column and do "trim". that should remove charecters at end and last.

 

Please use "enter data" in PQ to create your input data table and then do all operations.. Share the M Code and we can see. I strongly believe cleanup should be done in PQ and not DAX/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors