Forum Discussion

mjcrow17's avatar
mjcrow17
New Member
2 years ago
Solved

generating list with dynamic loop threshold issue

I am trying to generate a list of months based on a contracts' start date and duration. I keep getting an error when making the loop threshold reference the duration column instead of a static number (which does work). 

List.Generate(()=>[x=[Start Date],i=0], each [i]<[Months_duration], each [i=[i]+1,x=Date.AddMonths([x],1)], each [x])

  • You can try this...

     

    = Table.AddColumn(PREVIOUSSTEP, "Custom", each let startDate = [Start Date], duration = [Months_duration] in List.Generate(()=>[x=startDate, i=0], each [i] <= duration, each [i=[i]+1, x=Date.AddMonths([x], 1)], each [x]))

     

2 Replies

  • You can try this...

     

    = Table.AddColumn(PREVIOUSSTEP, "Custom", each let startDate = [Start Date], duration = [Months_duration] in List.Generate(()=>[x=startDate, i=0], each [i] <= duration, each [i=[i]+1, x=Date.AddMonths([x], 1)], each [x]))

     

    • mjcrow17's avatar
      mjcrow17
      New Member

      Awesome! that worked! i did try creating the variable in the within the list but pulling out before worked! thanks so much!