Results 1 to 2 of 2

Thread: PQ - Power Query split?

  1. #1
    Sir Moderator sandy666's Avatar
    Join Date
    May 2018
    Posts
    237
    Rep Power
    7

    Cool PQ - Power Query split?

    (question from the web)

    I have a table with a column that has full paths/categories on it:

    BaseCategory/SubCategoryA/SubCategoryA.1/SubCategoryA.1.1
    OtherBaseCategory/SubCategoryB/SubCategoryB.1

    How can I split the paths/categories using Power Query so that I can get all the previous categories as well:

    Full Category Result
    BaseCategory/SubCategoryA/SubCategoryA.1/SubCategoryA.1.1 BaseCategory
    BaseCategory/SubCategoryA/SubCategoryA.1/SubCategoryA.1.1 BaseCategory/SubCategoryA
    BaseCategory/SubCategoryA/SubCategoryA.1/SubCategoryA.1.1 BaseCategory/SubCategoryA/SubCategoryA.1
    BaseCategory/SubCategoryA/SubCategoryA.1/SubCategoryA.1.1 BaseCategory/SubCategoryA/SubCategoryA.1/SubCategoryA.1.1
    OtherBaseCategory/SubCategoryB/SubCategoryB.1 OtherBaseCategory
    OtherBaseCategory/SubCategoryB/SubCategoryB.1 OtherBaseCategory/SubCategoryB
    OtherBaseCategory/SubCategoryB/SubCategoryB.1 OtherBaseCategory/SubCategoryB/SubCategoryB.1

    Code:
    let
    //(CC)sandy666
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        Group = Table.Group(Source, {"Full Category"}, {{"Count", each _, type table}}),
        SCount = Table.AddColumn(Group, "SCount", each List.Count(Text.Split([Full Category],"/"))-1),
        List = Table.AddColumn(SCount, "List", each List.Sort({0..[SCount]}, Order.Descending)),
        Expand = Table.ExpandListColumn(List, "List"),
        Subtract = Table.AddColumn(Expand, "Subtraction", each [SCount] - [List], type number),
        TBD = Table.AddColumn(Subtract, "Result", each Text.BeforeDelimiter([Full Category], "/", [Subtraction]), type text),
        TSC = Table.SelectColumns(TBD,{"Result"})
    in
        TSC
    Last edited by sandy666; 04-06-2021 at 04:32 PM.
    sandy
    I know you know but I forgot my Crystal Ball and don't know what you know also I may not remember what I did weeks, months or years ago so answer asap. Thinking doesn't hurt

  2. #2
    Sir Moderator sandy666's Avatar
    Join Date
    May 2018
    Posts
    237
    Rep Power
    7

    Cool

    Here is another option

    Source Expected
    Full Category Result
    BaseCategory/SubCategoryA/SubCategoryA.1/SubCategoryA.1.1 BaseCategory
    OtherBaseCategory/SubCategoryB/SubCategoryB.1 BaseCategory/SubCategoryA
    BaseCategory/SubCategoryA/SubCategoryA.1
    BaseCategory/SubCategoryA/SubCategoryA.1/SubCategoryA.1.1
    OtherBaseCategory
    OtherBaseCategory/SubCategoryB
    OtherBaseCategory/SubCategoryB/SubCategoryB.1

    Code:
    let
    //(CC)sandy666 
        Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
        SCount = Table.AddColumn(Source, "SCount", each List.Count(Text.Split([Full Category],"/"))-1),
        List = Table.AddColumn(SCount, "List", each List.Sort({0..[SCount]}, Order.Descending)),
        Expand = Table.ExpandListColumn(List, "List"),
        Subtract = Table.AddColumn(Expand, "Subtraction", each [SCount] - [List], type number),
        TBD = Table.AddColumn(Subtract, "Result", each Text.BeforeDelimiter([Full Category], "/", [Subtraction]), type text),
        TSC = Table.SelectColumns(TBD,{"Result"})
    in
        TSC
    Last edited by sandy666; 04-23-2021 at 12:45 PM.
    sandy
    I know you know but I forgot my Crystal Ball and don't know what you know also I may not remember what I did weeks, months or years ago so answer asap. Thinking doesn't hurt

Similar Threads

  1. PQ - Choose power query table destination range & sheet
    By sandy666 in forum Power Query, Power Pivot and Power BI
    Replies: 0
    Last Post: 03-02-2021, 02:01 AM
  2. PQ - Power Query: search multiple columns against a list of values?
    By sandy666 in forum Power Query, Power Pivot and Power BI
    Replies: 0
    Last Post: 02-22-2021, 11:50 PM
  3. PQ - Transforming Text to Date in Power Query
    By sandy666 in forum Power Query, Power Pivot and Power BI
    Replies: 2
    Last Post: 02-22-2021, 01:08 AM
  4. PQ - How to get Total via Power Query
    By sandy666 in forum ETL PQ Tips and Tricks
    Replies: 0
    Last Post: 09-23-2020, 06:10 PM
  5. PQ - UnZip an use Content in Power Query
    By sandy666 in forum ETL PQ Tips and Tricks
    Replies: 0
    Last Post: 05-13-2020, 05:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •