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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
dommyw277
Helper IV
Helper IV

Splitting Column values

Hi, how would i split a column like this:

 

Category1

SR-01

SR-02

SR-03

Category 2

SR-05

INC-01

INC-02

Category 3

INC-03

SR-06

etc etc

1 ACCEPTED SOLUTION

Hi @dommyw277 ,

Thanks for the screenshot  that really helps. As per my guess, the Invalid identifier error is coming from the way the column name Inc/SR is being referenced. Because the column name contains a slash (/), Power Query requires the #""  format.

So anywhere you have- [Inc/SR]

please change it to - [#"Inc/SR"]

And in your filter step

each [#"Inc/SR"] <> null and [#"Inc/SR"] <> ""

Once the column is referenced with [#"...."] , the syntax error should be resolved.


Hope this helps please give it a try. If anything still comes up, feel free to share another screenshot and we can take a look.

View solution in original post

25 REPLIES 25

This is what i have minus the top 2 lines which contain info i cant post eg source of files:

 

#"Removed Top Rows" = Table.Skip(#"Changed Type",5),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"RequestID", type text}, {"Request Mode", type text}, {"Technician", type text}, {"Created Time", type datetime}, {"Completed Time", type datetime}, {"Subject", type text}, {"Request Type", type text}})
#"Added Custom" = Table.AddColumn(Source, "Inc/SR", each if Text.StartsWith([RequestID],"SR-",Comparer.OrdinalIgnoreCase) or Text.StartsWith([RequestID],"INC-",Comparer.OrdinalIgnoreCase) then [RequestID] else null),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Category", each if [#"Inc/SR"]=null then [RequestID] else null),
#"Filled Down" = Table.FillDown(#"Added Custom1",{"Category"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each [#"Inc/SR"] <> null and [#"Inc/SR"] <> ""),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"RequestID"})
in
#"Changed Type1"

I then get an error:

Expression.SyntaxError: Token ',' expected.

MasonMA
Community Champion
Community Champion

Hi, 

 

You'd need 3 major Power Query UI steps. For your sample data, first add a column, 

MasonMA_0-1764951110248.png

Fill down 'Custom' Column. 

MasonMA_1-1764951166002.png

Filter out 'Category' in Column1 

MasonMA_3-1764951400247.png

MasonMA_2-1764951267473.png

The rest would be renaming, reordering etc. 

 

Same logic for your new data @dommyw277 

MasonMA_0-1764951739704.png

Shubham_rai955
Memorable Member
Memorable Member

In Power Query Editor, add an Index column, then use a custom function to split grouped values into separate Category/Item rows.​

Solution Steps

  • Add Index: Select column > Add Column > Index Column (from 0).​

  • Custom Column with M formula:

 
 
if Text.StartsWith([Column], "Category") then { [Column], null } else { Text.BeforeDelimiter(Text.From([Column]), "Category" & Number.From(Text.PositionOf(Text.From([Column]), "Category")), [Column] }
  • Expand List: Expand the new list column to rows (Attribute=Category, Value=Item).​​

Advanced M Code (Advanced Editor)

Replace your query step with:

 
 
let Source = ..., #"Added Index" = Table.AddIndexColumn(Source, "Index",0,1), #"Split Rows" = Table.ExpandListColumn( Table.AddColumn(#"Added Index", "Split", each List.Generate( () => [i=0, cat=Text.Select([Column], each Text.Contains("Category"))], each [i] < List.Count(Text.Split([Column],"#(lf)")), each [i=[i]+1] ) ), "Split" )

Filter nulls, remove Index.​

dommyw277
Helper IV
Helper IV

thank you. I want to put all the categories in one column and the SR plus INC in another column 

 

FBergamaschi
Solution Sage
Solution Sage

Can you explain what outcome you want to get?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.