Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Posting as I have been struggling with this.
Input (there are other columns in this table, but these are the ones that need transformation.)
ID | Name | Count |
FF12/33 | John, Jame | 4 |
FF66/D2 | Bob | 1 |
FF13/4F | Carter, Carlie, Charlie, Charlie, Cat | 5 |
FF0/45 | Zed, Zeus | 2 |
FFLL-34 | Harry | 6 |
Things that need to happen:
Expected output:
ID | Name | Count |
FF12/33 - 1 | John | 2 |
FF12/33 - 2 | Jame | 1 |
FF66/D2 | Bob | 1 |
FF13/4F - 1 | Carter | 1 |
FF13/4F - 2 | Carlie | 1 |
FF13/4F - 3 | Charlie | 1 |
FF13/4F - 4 | Charlie | 1 |
FF13/4F - 5 | Cat | 1 |
FF0/45 - 1 | Zed | 1 |
FF0/45 - 2 | Zeus | 1 |
FFLL-34 | Harry | 6 |
Thank you so much for your time and help.
Solved! Go to Solution.
Hi @RookieEngineer ,
Try the following example code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnMzNNI3NlbSUfLKz8jTUfBKzE0FckyUYnVAkmZm+i5GQL5TfhKQNISKGhrrm7gB+c6JRSWpRToKQDonMxVIZ2AwEkuA6kyh+gz0TUyB3KjUFB2FqNTSYiDbCCrl46NrbALkeyQWFVUCaTOl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name = _t, Count = _t]),
chgTypes = Table.TransformColumnTypes(Source,{{"Count", Int64.Type}}),
// Relevant steps from here ====>
splitNameByDelim = Table.ExpandListColumn(Table.TransformColumns(chgTypes, {{"Name", Splitter.SplitTextByDelimiter(", ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Name"),
groupIDNested = Table.Group(splitNameByDelim, {"ID"}, {{"data", each _, type table [ID=nullable text, Name=nullable text, Count=nullable number]}}),
addID_Index = Table.TransformColumns(groupIDNested, {"data", each Table.AddIndexColumn(_, "ID_Index", 1, 1)}),
addID_SplitCount = Table.AddColumn(addID_Index, "ID_SplitCount", each Table.RowCount([data])),
expandData = Table.ExpandTableColumn(addID_SplitCount, "data", {"Name", "Count", "ID_Index"}, {"Name", "Count", "ID_Index"}),
replaceID = Table.ReplaceValue(expandData,each [ID], each if [ID_SplitCount] = 1 then [ID] else Text.Combine({[ID], Text.From([ID_Index])}, " - ") ,Replacer.ReplaceText, {"ID"}),
addNewCount = Table.AddColumn(replaceID, "NewCount", each [Count] / [ID_SplitCount]),
remOthCols = Table.SelectColumns(addNewCount,{"ID", "Name", "NewCount"})
in
remOthCols
It transforms this:
...into this:
Pete
Proud to be a Datanaut!
let
to_list = Table.ToList(
Source,
(x) => ((names) =>
List.Zip(
{
if names[count] = 1 then {x{0}} else List.Transform({1..names[count]}, (w) => x{0} & Text.Format(" - #{0}", {w})),
names[names],
List.Repeat({x{2} / names[count]}, names[count])
}
)
)([names = Text.Split(x{1}, ", "), count = List.Count(names)])
),
to_table = Table.FromList(List.Combine(to_list), (x) => x, Table.ColumnNames(Source))
in
to_table
Hi @RookieEngineer,
Thanks for reaching out to the Microsoft Fabric Community Forum.
If my response solved your query, please mark it as the Accepted solution to help others find it easily!
And if my answer was helpful, I'd really appreciate a 'Kudos'
you can use this code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnMzNNI3NlbSUfLKz8jTUfBKzE0FckyUYnVAkmZm+i5GQL5TfhKQNISKGhrrm7gB+c6JRSWpRToKQDonMxVIZ2AwEkuA6kyh+gz0TUyB3KjUFB2FqNTSYiDbCCrl46NrbALkeyQWFVUCaTPc4rEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name = _t, Count = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Count", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Split([Name],",")),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "New Count", each [Count]/List.Count([Custom])),
#"Multiplied Column" = Table.TransformColumns(#"Added Custom1", {{"Custom", each if List.Count(_)=1 then _ else List.Transform(List.Positions(_), (x)=> Text.From(x+1) & " " & _{x})}}),
#"Expanded Custom" = Table.ExpandListColumn(#"Multiplied Column", "Custom")
in
#"Expanded Custom"
thank you for your response. Unfortunately I ended up with this!
Hi @RookieEngineer ,
Try the following example code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnMzNNI3NlbSUfLKz8jTUfBKzE0FckyUYnVAkmZm+i5GQL5TfhKQNISKGhrrm7gB+c6JRSWpRToKQDonMxVIZ2AwEkuA6kyh+gz0TUyB3KjUFB2FqNTSYiDbCCrl46NrbALkeyQWFVUCaTOl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name = _t, Count = _t]),
chgTypes = Table.TransformColumnTypes(Source,{{"Count", Int64.Type}}),
// Relevant steps from here ====>
splitNameByDelim = Table.ExpandListColumn(Table.TransformColumns(chgTypes, {{"Name", Splitter.SplitTextByDelimiter(", ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Name"),
groupIDNested = Table.Group(splitNameByDelim, {"ID"}, {{"data", each _, type table [ID=nullable text, Name=nullable text, Count=nullable number]}}),
addID_Index = Table.TransformColumns(groupIDNested, {"data", each Table.AddIndexColumn(_, "ID_Index", 1, 1)}),
addID_SplitCount = Table.AddColumn(addID_Index, "ID_SplitCount", each Table.RowCount([data])),
expandData = Table.ExpandTableColumn(addID_SplitCount, "data", {"Name", "Count", "ID_Index"}, {"Name", "Count", "ID_Index"}),
replaceID = Table.ReplaceValue(expandData,each [ID], each if [ID_SplitCount] = 1 then [ID] else Text.Combine({[ID], Text.From([ID_Index])}, " - ") ,Replacer.ReplaceText, {"ID"}),
addNewCount = Table.AddColumn(replaceID, "NewCount", each [Count] / [ID_SplitCount]),
remOthCols = Table.SelectColumns(addNewCount,{"ID", "Name", "NewCount"})
in
remOthCols
It transforms this:
...into this:
Pete
Proud to be a Datanaut!
Hello Pete, thank you. I've run this and can confirm I'm getting the desired output.
Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂
Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
10 | |
7 | |
7 | |
6 | |
6 |