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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Oros
Post Partisan
Post Partisan

'Split' a column or process query to create 2 columns

Hello. 

 

I have a column PACKAGING that has diffirent UNIT data (G, G*, GR, L, LT, KG, UN).  There are also some records where the values are enclosed in parenthesis ( ).

 

Here is the column that I would like to 'split' this column (EXISTING COLUMN) to create 2 columns (RESULTS COLUMNS).  Thanks.

 

Oros_1-1653681639508.png

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Oros - Maybe there's a better way...

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY1LCoAwDETv4kpFZJKSoifowupCFAKl97+Gqdru5uUzL6WOoE4QujxZZqWZJVZgQjg/8OqU2x2UgDBWcL7dQQXYW0O/KNty+Ni+tr9BlOL1RtOYs85L8X38WcyzFmd+AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Packaging = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,"(","",Replacer.ReplaceText,{"Packaging"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",")","",Replacer.ReplaceText,{"Packaging"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Replaced Value1", "Packaging", Splitter.SplitTextByEachDelimiter({"X"}, QuoteStyle.Csv, false), {"Packaging.1", "Packaging.2"}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter", "Packaging.2", Splitter.SplitTextByEachDelimiter({"X"}, QuoteStyle.Csv, false), {"Packaging.1.1", "Packaging.1.2"}),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Split Column by Delimiter1", "Packaging.1.1", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9", "."}, c)), {"Packaging.1.1.1", "Packaging.1.1.2"}),
    #"Split Column by Character Transition1" = Table.SplitColumn(#"Split Column by Character Transition", "Packaging.1.2", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), {"Packaging.1.2.1", "Packaging.1.2.2"}),
    #"Merged Columns" = Table.CombineColumns(#"Split Column by Character Transition1",{"Packaging.1.1.2", "Packaging.1.2.2"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged"),
    #"Changed Type" = Table.TransformColumnTypes(#"Merged Columns",{{"Packaging.1", type number}, {"Packaging.1.1.1", type number}, {"Packaging.1.2.1", type number}}),
    #"Replaced Value2" = Table.ReplaceValue(#"Changed Type",null,1,Replacer.ReplaceValue,{"Packaging.1.2.1"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value2", "Custom", each [Packaging.1] * [Packaging.1.1.1] * [Packaging.1.2.1]),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Packaging.1", "Packaging.1.1.1", "Packaging.1.2.1", "Custom", "Merged"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Reordered Columns",{"Custom", "Merged"})
in
    #"Removed Other Columns"

RETURNS

image.png

You can modify the function below to 'switch' abbreviations to full text values

fnSwitch( )

(input) =>
 
let
 
values = {
 
  {1, "Jul"},
  {2, "Aug"},
  {3, "Sep"},
  {4, "Oct"},
  {5, "Nov"},
  {6, "Dec"},
  {7, "Jan"},
  {8, "Feb"},
  {9, "Mar"},
  {10, "Apr"},
  {11, "May"},
  {12, "Jun"},
  {input, "Undefined"}
 
},
 
Result = List.First(List.Select(values, each _{0}=input)){1}
 
in
 
Result

 

@freginier had the right idea to start but you have to modify the built in GUI code to exclude the "."

Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9", "."}, c))





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

6 REPLIES 6
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Oros - Maybe there's a better way...

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY1LCoAwDETv4kpFZJKSoifowupCFAKl97+Gqdru5uUzL6WOoE4QujxZZqWZJVZgQjg/8OqU2x2UgDBWcL7dQQXYW0O/KNty+Ni+tr9BlOL1RtOYs85L8X38WcyzFmd+AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Packaging = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,"(","",Replacer.ReplaceText,{"Packaging"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",")","",Replacer.ReplaceText,{"Packaging"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Replaced Value1", "Packaging", Splitter.SplitTextByEachDelimiter({"X"}, QuoteStyle.Csv, false), {"Packaging.1", "Packaging.2"}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter", "Packaging.2", Splitter.SplitTextByEachDelimiter({"X"}, QuoteStyle.Csv, false), {"Packaging.1.1", "Packaging.1.2"}),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Split Column by Delimiter1", "Packaging.1.1", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9", "."}, c)), {"Packaging.1.1.1", "Packaging.1.1.2"}),
    #"Split Column by Character Transition1" = Table.SplitColumn(#"Split Column by Character Transition", "Packaging.1.2", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), {"Packaging.1.2.1", "Packaging.1.2.2"}),
    #"Merged Columns" = Table.CombineColumns(#"Split Column by Character Transition1",{"Packaging.1.1.2", "Packaging.1.2.2"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged"),
    #"Changed Type" = Table.TransformColumnTypes(#"Merged Columns",{{"Packaging.1", type number}, {"Packaging.1.1.1", type number}, {"Packaging.1.2.1", type number}}),
    #"Replaced Value2" = Table.ReplaceValue(#"Changed Type",null,1,Replacer.ReplaceValue,{"Packaging.1.2.1"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value2", "Custom", each [Packaging.1] * [Packaging.1.1.1] * [Packaging.1.2.1]),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Packaging.1", "Packaging.1.1.1", "Packaging.1.2.1", "Custom", "Merged"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Reordered Columns",{"Custom", "Merged"})
in
    #"Removed Other Columns"

RETURNS

image.png

You can modify the function below to 'switch' abbreviations to full text values

fnSwitch( )

(input) =>
 
let
 
values = {
 
  {1, "Jul"},
  {2, "Aug"},
  {3, "Sep"},
  {4, "Oct"},
  {5, "Nov"},
  {6, "Dec"},
  {7, "Jan"},
  {8, "Feb"},
  {9, "Mar"},
  {10, "Apr"},
  {11, "May"},
  {12, "Jun"},
  {input, "Undefined"}
 
},
 
Result = List.First(List.Select(values, each _{0}=input)){1}
 
in
 
Result

 

@freginier had the right idea to start but you have to modify the built in GUI code to exclude the "."

Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9", "."}, c))





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Thanks @ChrisMendoza 

Hi @ChrisMendoza ,

 

Thank you for your quick reply.

 

This is what I have in the advance query editor.  Do I just replace them all with the query that you wrote? Thanks again.

 

let
Source = Dynamics365BusinessCentral.ApiContents(null, null, null),
PRODUCTION = Source{[Name="PRODUCTION"]}[Data],
#"MAIN DATA" = PRODUCTION{[Name="MAIN DATA"]}[Data],
WebServices = #"MAIN DATA"{[Name="WebServices"]}[Data],
Item_Card_table = WebServices{[Name="Item_Card",Signature="table"]}[Data]

in
Item_Card_table

Hi @Oros ,

I create a sample pbix file, which is based on the response given by @ChrisMendoza with some minor changes, please check if it is the result you want. Please find the details the attachment.
1. Change the function fnSwitch( )

(input) =>
let
values = {
  {"G", "GRAMS"},
  {"GR", "GRAMS"},
  {"G*", "GRAMS"},
  {"L", "LITERS"},
  {"LT", "LITERS"},
  {"ML", "MLITERS"},
  {"KG", "KILOS"},
  {"UN", "UNIT"},
  {input, "Undefined"}
},
Result = List.First(List.Select(values, each _{0}=input)){1}
in
Result

2. Add a custom column to call the value inside the function

yingyinr_1-1653982873700.png

If you still not know how to achive it, please provide some sample data in Item_card_table. It is better if you can provide a simiplified pbix file with us. Thank you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
freginier
Solution Specialist
Solution Specialist

You can do this using split function in power query, try to use split with "Digit to non digit" you should have multiple column and you just have to do your calculation

freginier_0-1653682145880.png

 

HI @freginier ,

 

Thank you for the quick reply.  I did it but the 12X1.25L becomes 12 | 1 |  .25  |  L.  The .25 becomes separated.  Thanks again.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.