• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Parsing numbers from single cell

Gregg Wolin

Member
I need to create a process that automates the population of a simple table. I manage the development of residential subdivisions and builders purchase lots within discreet “phases” of lots. When starting a new project, we agree on which lots are in each phase and the agreements list the phasing I the following format:

Phase 1: Lots 1-3, 16-20
Phase 2: Lots 4, 5, 7, 9-15
Phase 3: Lots 6, 8

I’d like the ability to enter the lot numbers for each phase in a single cell (as above) and have excel parse the numbers and populate a 3-column Phasing table.

I’m also open to other methods to accomplish this task (userform, wizards, etc.) but I thought I’d start with the most simple representation.
 
Please upload to this site a workbook, showing sample data as entered and what your expected results should look like. Be sure that your sample is representative of your actual data. This will expedite and help to resolve your issue.
 
Please upload to this site a workbook, showing sample data as entered and what your expected results should look like. Be sure that your sample is representative of your actual data. This will expedite and help to resolve your issue.
 

Attachments

  • chandoo-parse.xlsx
    11.2 KB · Views: 19
Hi:

May be this? I have used power query to manipulate the data in the format you need.

Thanks
 

Attachments

  • chandoo-parse.xlsx
    19.8 KB · Views: 9
Hi @Gregg Wolin , though it surely works. Did you use the refresh button after the update? In the result table click right mouse and select "refresh" from the menu.
Or did you got an error message after having added numbers (like phase 4)?

EDIT
This slightly adapted query might solve your problem.
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    GetList = Table.AddColumn(#"Changed Type", "Custom", each Text.Split([Column2],",")),
    ExpandLists = Table.ExpandListColumn(GetList, "Custom"),
    #"Inserted Text Before Delimiter" = Table.AddColumn(ExpandLists, "Text Before Delimiter", each Text.BeforeDelimiter([Custom], "-"), type text),
    #"Inserted Text After Delimiter" = Table.AddColumn(#"Inserted Text Before Delimiter", "Text After Delimiter", each Text.AfterDelimiter([Custom], "-"), type text),
    MakeList = Table.AddColumn(#"Inserted Text After Delimiter", "Custom.1", each try {Value.FromText([Text Before Delimiter])..Value.FromText([Text After Delimiter])} otherwise {[Text Before Delimiter]}),
    #"Removed Columns" = Table.RemoveColumns(MakeList,{"Custom", "Text Before Delimiter", "Text After Delimiter", "Column2"}),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Removed Columns", "Custom.1"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom.1",{{"Custom.1", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type1", "Index", 0, 1),
    #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[Column1]), "Column1", "Custom.1"),
    #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns1"
 
Last edited:
Hi @Gregg Wolin , though it surely works. Did you use the refresh button after the update? In the result table click right mouse and select "refresh" from the menu.
Or did you got an error message after having added numbers (like phase 4)?
My apologies - I didn't realize the table needed to be refreshed. I guess I need to learn some PowerQuery.
Thanks!
 
I thought so :). Also I tested Nebu's solution and it is already working fine when you add items. So my previous EDIT in #6 can be dismissed.

As stated already many times now: Power Query is not so difficult as one may think. Already with the basics you go a long way on the road to wizardry.
 
I'd not recommend returning single table using staggered stack. Since dimensions for each phase will not match, it will create more headache than not and will bloat resulting table.

Personally I'd structure table like below.
PhaseLotNumIndex
Phase 111
Phase 122
Phase 133
Phase 1164
Phase 1175
Phase 1186
Phase 1197
Phase 1208
Phase 241
Phase 252
Phase 273
Phase 294
Phase 2105
Phase 2116
Phase 2127
Phase 2138
Phase 2149
Phase 21510
Phase 361
Phase 382

Then put it into PivotTable to summarize using Index as row label.
59207

See attached.

EDIT: First sentence for clarity.
 

Attachments

  • chandoo-parse.xlsx
    102.2 KB · Views: 3
Last edited:
Nice custom function, though I think List.Generate() may be a bit of a stretch for starters.
Added the index per phase in my solution as per your suggestion, Chihiro. I did not take the time to rename
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    GetList = Table.AddColumn(Source, "Custom", each Text.Split([Column2],",")),
    ExpandLists = Table.ExpandListColumn(GetList, "Custom"),
    #"Inserted Text Before Delimiter" = Table.AddColumn(ExpandLists, "Text Before Delimiter", each Text.BeforeDelimiter([Custom], "-"), type text),
    #"Inserted Text After Delimiter" = Table.AddColumn(#"Inserted Text Before Delimiter", "Text After Delimiter", each Text.AfterDelimiter([Custom], "-"), type text),
    MakeList = Table.AddColumn(#"Inserted Text After Delimiter", "Custom.1", each try {Value.FromText([Text Before Delimiter])..Value.FromText([Text After Delimiter])} otherwise {[Text Before Delimiter]}),
    #"Removed Columns" = Table.RemoveColumns(MakeList,{"Custom", "Text Before Delimiter", "Text After Delimiter", "Column2"}),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Removed Columns", "Custom.1"),
    #"Grouped Rows" = Table.Group(#"Expanded Custom.1", {"Column1"}, {{"AsTable", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([AsTable],"Index",1,1)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Custom.1", "Index"}, {"Custom.Custom.1", "Custom.Index"}),
    #"Removed Columns2" = Table.RemoveColumns(#"Expanded Custom",{"AsTable"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns2", List.Distinct(#"Removed Columns2"[Column1]), "Column1", "Custom.Custom.1"),
    #"Changed Type" = Table.TransformColumnTypes(#"Pivoted Column",{{"Phase 1", Int64.Type}, {"Phase 2", Int64.Type}, {"Phase 3", Int64.Type}})
in
    #"Changed Type"
 
Wow! I'd be lying if I said i had ANY idea how this works but I appreciate the solutions. I clearly need to invest some time with PowerQuery.
 
Back
Top