cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
theo Regular Visitor
Regular Visitor

how to use list.generate to pass as a loop

Hi.  This might be simple but still a newbie here.  Would appreciate any help to push me in the right direction.

What I am trying to do is count the rows the equal to
current tix-1

current tix-2

current tix-3

current tix-4

current tix-5

 

= Table.AddColumn(#"Added Custom1", "Count", each List.Count(Table.SelectRows(#"Added Custom1", (C) => 
    (
        [Tix]>=C[Tix]-(List.Generate(()=>1,each _ 5, each _ - 1))
        )
        )[Column1]))

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
theo Regular Visitor
Regular Visitor

Re: how to use list.generate to pass as a loop

Through research, I found the solution:

 

= 

      Table.AddColumn(

        #"Added Custom2", 

        "Count", each List.Sum(

                                    List.Generate(

                        () => [Count=List.Count(

                                        Table.SelectRows(

                                            #"Added Custom2", 

                                            (C) => C[Tix] = [Tix]-Continue)

                                                        [Column1]),

                                                        Continue =1],

                        each [Continue]<=10,

                        each [Final_Item = [Final_Item], 

                              Continue =[Continue]+1],

                        each [Count])))

View solution in original post

4 REPLIES 4
Community Support Team
Community Support Team

Re: how to use list.generate to pass as a loop

Hi @theo ,

Based on your description, I still a little confused about your scenario.

If it is convenient, could you share the data sample with table format and your desired output so that we could help further on it?

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
theo Regular Visitor
Regular Visitor

Re: how to use list.generate to pass as a loop

@v-piga-msft 

Basically I am trying to count the number of rows of tix based on the difference with current tix value.  Below is the snippet.  It is the same as putting a range criteria like (Tix >=current Tix-5 and Tix <=current Tix-1)
like for value 6,991,905 the count will be only 1 (which is 6991904) which is within (6991904 to 69991905). 

+-------------+------------+
 TIX          |TIX count   |
5,000,243     | 0          |
6,991,904     | 0          |
6,991,905     | 1          |
6,991,906     | 2          |
6,991,907     | 3          |
6,991,908     | 4          |
7,000,234     | 0          |
+-------------+------------+

I simplify the problem but I will be using the looped range in more complicated formula like Tix - 1/2 x2+41/2 x.
In this case I want to count the rows equal to that equation where x could be from 1 to 10.

theo Regular Visitor
Regular Visitor

Re: how to use list.generate to pass as a loop

Hi @v-piga-msft 

Tried another code based I found online.  This also returns an error.

= Table.AddColumn(
#"Renamed Columns", 
"Count", 
List.Sum(
List.Generate(
() => [Continue = 1],
each [Continue]<6,
each [Count = 
List.Count(
Table.SelectRows(
#"Renamed Columns", 
(x) => x[Tix]-[Continue]= [Tix]))[Column1]],
each [Count])))
theo Regular Visitor
Regular Visitor

Re: how to use list.generate to pass as a loop

Through research, I found the solution:

 

= 

      Table.AddColumn(

        #"Added Custom2", 

        "Count", each List.Sum(

                                    List.Generate(

                        () => [Count=List.Count(

                                        Table.SelectRows(

                                            #"Added Custom2", 

                                            (C) => C[Tix] = [Tix]-Continue)

                                                        [Column1]),

                                                        Continue =1],

                        each [Continue]<=10,

                        each [Final_Item = [Final_Item], 

                              Continue =[Continue]+1],

                        each [Count])))

View solution in original post

Helpful resources

Announcements
Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Top Kudoed Authors
Users Online
Currently online: 160 members 1,624 guests
Please welcome our newest community members: