SOLVED

Loop Command in Power Query

Copper Contributor

Hi to all,

 

Stuck up with large set of data which has multiple variables and overlapping sets of values.

 

To overcome the same, Through "Power Query", I have managed to get non-overlapped value for single item in sheet 'Length Achieved - Single Item'. (Item1 - A is having value of 400)

 

However, I'm unable to apply the same with Multiple Item in sheet 'Length Achieved - Multiple Item'.. ((Item1 - A value changes to 950)

 

I need help in Running Same Sets of Command in Loop. Sheet Attached.

 

Thanks in Advance..

7 Replies

@aditya Not sure if I fully comprehended your problem, but perhaps the attached workbook contains the result you are after. I've added a query "Table1 (2)" that loads a four row table.

@Riny_van_Eekelen  Attached solves one part of problem of looping.

 

However, It is not removing and capturing overlapping & non-overlapping data. Sample data for single item is shown below. And Power Query of Single Item is attached in previous post named as "Length Achieved -Single Item".

 

Data with same set of (ITEM & SIDE) Resultant
ItemSideStartEndValue ItemSideStartEndLENGTH
Item1A1003001 Item1A100400300
Item1A2002501 Item1A500600100
Item1A1001501 Item1A750850100
Item1A5006001 Item1A9001000100
Item1A2804001      
Item1A7508001 Item1A  600
Item1A8008501      
Item1A90010001      

 

 

@aditya Perhaps like in the attached file. Split off the original query and loaded two tables. One before aggregation and one after.

best response confirmed by aditya (Copper Contributor)
Solution

@aditya 

As variant, to receive such result

image.png

and ignoring column Value in source data, not sure for what it is needed, we may generate list from start to end for each record, group table on Item and Side, as aggregation union lists for the groups and count them. Entire script is

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Add column with lists of points" = Table.AddColumn(
        Source,
        "List values",
        each {[Start]+1..[End]}
    ),
    #"Groupe by Items and Sides and count union" = Table.Group(
        #"Add column with lists of points",
        {"Item", "Side"},
        {
            {"Count",
             each List.Count(List.Union([List values]))
            }
        }
    )
in
    #"Groupe by Items and Sides and count union"
Thanks, Works exactly with what I was looking for..

I'm beginner level for Power Query, Can you suggest some good book / weblinks for getting more hands on Power Query Advance Commands.

@Riny_van_EekelenThanks for the efforts mate.. But it misses ranges between multiple data set as under.

Item1A100300
Item1A200250
Item1A100150
Item1A500600
Item1A280400
Item1A750800
Item1A800850
Item1A9001000

 

Should provide resultant as

 

MergedStartEndSubtraction
Item1|A100400300
Item1|A500600100
Item1|A750850100
Item1|A9001000100

 

Hence, Total of Item1|A shall be 600.

 

Solution provided by @Sergei Baklan covers the same.

 

Thanks Amigos.

@aditya 

You are welcome, glad to help. As for resources - lot of them. You may start from Gil Raviv book https://datachant.com/next/ and his blog, lot of topics on Ken Puls' excelguru.ca , next could be Chris Webb' BI blog. 

1 best response

Accepted Solutions
best response confirmed by aditya (Copper Contributor)
Solution

@aditya 

As variant, to receive such result

image.png

and ignoring column Value in source data, not sure for what it is needed, we may generate list from start to end for each record, group table on Item and Side, as aggregation union lists for the groups and count them. Entire script is

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Add column with lists of points" = Table.AddColumn(
        Source,
        "List values",
        each {[Start]+1..[End]}
    ),
    #"Groupe by Items and Sides and count union" = Table.Group(
        #"Add column with lists of points",
        {"Item", "Side"},
        {
            {"Count",
             each List.Count(List.Union([List values]))
            }
        }
    )
in
    #"Groupe by Items and Sides and count union"

View solution in original post