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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
aklaur
New Member

Parse Numbers from Text to create Number List and add text to each value

  Trying to  create a list from Range with added Text before (or after?)   Combining Text from list.

 Goal:

AreaExpanded
Lots 1 ‐ 10Lot 1, Lot 2, Lot 3, Lot 4, Lot 5, Lot 6, Lot 7, Lot 8, Lot 9, Lot 10
Lots 5-6 &9Lot 5, Lot 6, Lot 9
Lots 3-5 & 7-9Lot 3, Lot 4, Lot 5, Lot 7, Lot 8, Lot 9

 

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Area", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Combine(List.RemoveNulls(List.Transform(Text.ToList([Area]),each if Value.Is(Value.FromText(_), type number) then _ else null)))),
    #"Inserted First Characters" = Table.AddColumn(#"Added Custom", "First Characters", each Text.Start([Custom], 1), type text),
    #"Split Column by Positions" = Table.SplitColumn(#"Inserted First Characters", "Custom", Splitter.SplitTextByPositions({1}), {"Custom.1"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Positions",{{"Custom.1", Int64.Type}, {"First Characters", Int64.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Expanded", each Text.Combine(List.Transform(List.Transform(List.Numbers([First Characters],[Custom.1]),each Number.ToText(_)),each Text.Combine("Lot",(_))),","))
in
    #"Added Custom1"

 I know the previous Query may not work for multiple Ranges, perhaps a better way to Parse.

Mostly stuck on the last line though:

#"Added Custom1" = Table.AddColumn(#"Changed Type1", "Expanded", each Text.Combine(List.Transform(List.Transform(List.Numbers([First Characters],[Custom.1]),each Number.ToText(_)),each Text.Combine("Lot",(_))),","))

 

 

1 ACCEPTED SOLUTION
MarkLaf
Memorable Member
Memorable Member

I think this gets what you want.

 

let
    Source = OriginalAreas,
    ExpandLots = Table.AddColumn(
        Source,
        "Expanded",
        each
            [
                removeLots = Text.Trim(Text.Replace([Area], "Lots", "")),
                ampSplit = Text.Split(removeLots, "&"),
                dashSplit = List.Transform(
                    ampSplit,
                    each [
                        split = Text.SplitAny(_, "-‐"), 
                        toNum = List.Transform(split, Number.FromText)
                    ][toNum]
                ),
                expandDash = List.Transform(dashSplit, each if List.Count(_) = 1 then _ else {_{0}.._{1}}),
                combo = List.Combine(expandDash),
                concatLot = "Lot " & Text.Combine(List.Transform(combo, Text.From), ", Lot ")
            ][concatLot],
        type text
    )
in
    ExpandLots

 

MarkLaf_0-1752178894581.png

 

View solution in original post

2 REPLIES 2
MarkLaf
Memorable Member
Memorable Member

I think this gets what you want.

 

let
    Source = OriginalAreas,
    ExpandLots = Table.AddColumn(
        Source,
        "Expanded",
        each
            [
                removeLots = Text.Trim(Text.Replace([Area], "Lots", "")),
                ampSplit = Text.Split(removeLots, "&"),
                dashSplit = List.Transform(
                    ampSplit,
                    each [
                        split = Text.SplitAny(_, "-‐"), 
                        toNum = List.Transform(split, Number.FromText)
                    ][toNum]
                ),
                expandDash = List.Transform(dashSplit, each if List.Count(_) = 1 then _ else {_{0}.._{1}}),
                combo = List.Combine(expandDash),
                concatLot = "Lot " & Text.Combine(List.Transform(combo, Text.From), ", Lot ")
            ][concatLot],
        type text
    )
in
    ExpandLots

 

MarkLaf_0-1752178894581.png

 

Awesome That Works! Thanks So much!   Much more complicated than my  average expertise.

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.