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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Awollet33
Helper I
Helper I

Data Cleaning Question

Hi PowerBi Community,

 

I am looking to make the column accounts disnict and create columns for the codes that correspond with the account. All help is greatly appreciated.

 

help.PNG

1 ACCEPTED SOLUTION
mussaenda
Super User
Super User

Hi @Awollet33

 

i think this question has been answered here before but not sure where I can find.

mussaenda_0-1617717279198.png

 

This is your desired output.

 

Here's the code. Paste on your blank query using Advanced Editor.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvF3V9JRSlSK1YlWcnYMAbKTwGwP/6BgVyAvGcwjpAoi4+sfCuYl4dCTjKIqRSk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Account = _t, Code = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Account", type text}, {"Code", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Account"}, {{"Count", each _, type table [Account=nullable text, Code=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Count], "Code")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ", "), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Custom", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Custom.1", type text}, {"Custom.2", type text}, {"Custom.3", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Count"})
in
    #"Removed Columns"

 

Take note, there is a shorter way to do this. If I find the link, I'll send you. That's shorter and easier.

But hope this helps.

 

 

View solution in original post

4 REPLIES 4
mussaenda
Super User
Super User

Hi @Awollet33

 

i think this question has been answered here before but not sure where I can find.

mussaenda_0-1617717279198.png

 

This is your desired output.

 

Here's the code. Paste on your blank query using Advanced Editor.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvF3V9JRSlSK1YlWcnYMAbKTwGwP/6BgVyAvGcwjpAoi4+sfCuYl4dCTjKIqRSk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Account = _t, Code = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Account", type text}, {"Code", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Account"}, {{"Count", each _, type table [Account=nullable text, Code=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Count], "Code")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ", "), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Custom", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Custom.1", type text}, {"Custom.2", type text}, {"Custom.3", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Count"})
in
    #"Removed Columns"

 

Take note, there is a shorter way to do this. If I find the link, I'll send you. That's shorter and easier.

But hope this helps.

 

 

Hi  @mussaenda ,

Thank you for your help and time! I am going to try and work through your code and it make it work for my data set. 

 

Thank you,

Adam

selimovd
Super User
Super User

Hey @Awollet33 ,

 

you can do that in Power Query with the Pivot function.

Check the following article on how to do that:

Pivot your Data using Power Query - Microsoft Power BI Community

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Hi @selimovd ,

 

The pivot function doesn't seem to be getting me the desired result I want. Thank you for your time in helping me figure out this problem.

 

Thanks,

Adam

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.