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
DSwezey
Helper III
Helper III

Split Value by deliminator and split other columns value

So I have a list of Sales reps and their commission amounts. There are a few cases where multiple sales reps worked on the same job and split the commission 50/50. How do I go about splitting the sales reps out into single Reps and then also splitting the Commission amount by 50% for each Rep so I still have accurate data?

 

DSwezey_0-1635175570940.png

 

Something similar to this:

DSwezey_1-1635175685170.png

 

1 ACCEPTED SOLUTION
Jakinta
Solution Sage
Solution Sage

Here is one way to do it.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1UNJRctRxUorViVYyNwVznMEcCwjHCcSNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Commision Amount" = _t, #"Sales Rep" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Commision Amount", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [Commision Amount] / (Text.Length(Text.Select ([Sales Rep], ",")) + 1), type number),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Commision Amount"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "Sales Rep"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Custom", "Commision Amount"}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Renamed Columns", {{"Sales Rep", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Sales Rep")
in
    #"Split Column by Delimiter"

Before

Jakinta_0-1635177526843.png

After

Jakinta_1-1635177546720.png

 

 

View solution in original post

6 REPLIES 6
Jakinta
Solution Sage
Solution Sage

Here is one way to do it.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1UNJRctRxUorViVYyNwVznMEcCwjHCcSNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Commision Amount" = _t, #"Sales Rep" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Commision Amount", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [Commision Amount] / (Text.Length(Text.Select ([Sales Rep], ",")) + 1), type number),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Commision Amount"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "Sales Rep"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Custom", "Commision Amount"}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Renamed Columns", {{"Sales Rep", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Sales Rep")
in
    #"Split Column by Delimiter"

Before

Jakinta_0-1635177526843.png

After

Jakinta_1-1635177546720.png

 

 

So I am very new to power BI/automate and am not quite sure how to interpret that. Any chance you can break it down and tell me what is going on? 

Create new blank query.

Replace all text in new query with code above and you can follow the steps.

The key is in the 3rd step. It is counting number of comas. Adding 1 on count we get the count of Sales Rep...

Ahh! I see.

I'm not sure what this json being referenced is. Am I changing the underlined section to the table I am using? EX: the table name is "Rep Commissions"

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1UNJRctRxUorViVYyNwVznMEcCwjHCcSNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Commision Amount" = _t, #"Sales Rep" = _t])

Since you have not provided the table, I had to create one. The json is that very table.

I had to start from somewhere. 🙂

You can copy/paste steps you need. Just change the referencing steps to steps in your query and it will work.

Or course haha! So where exactly do I pull from my "Rep Commissions" table in that code? AKA what am I replacing? (sorry, have never dealt with coding like this before)

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