Forum Discussion

ben-t's avatar
ben-t
Frequent Visitor
3 years ago
Solved

Help - List.Generate dates with variable frequency in months

Hi, I'm trying to generate a list of jobs to do in the next 2 years
I have a working custom column that provides me the list of dates. 
But my jobs have varying frequencies of 2-12 months intervals. 

 

List.Generate(() => [Next job],
each Date.From(_) <= Date.From(Date.AddYears(Date.EndOfYear(DateTime.LocalNow()), 1)),
each Date.AddMonths(_, 2))

 


Once I change my code to :

List.Generate(() => [Next job],
each Date.From(_) <= Date.From(Date.AddYears(Date.EndOfYear(DateTime.LocalNow()), 1)),
each Date.AddMonths( _ , [FREQUENCY]))


I get an error and when expanding further, it just shows me a date without any error message. 



Anyone knows what is causing this issue, and how I can work around it ?

Thanks

  • It might be a field access error.

    Try

    let freq = [FREQUENCY] in each Date.AddMonths( _ , freq))

     

6 Replies

  • HotChilli's avatar
    HotChilli
    Community Champion

    It might be a field access error.

    Try

    let freq = [FREQUENCY] in each Date.AddMonths( _ , freq))

     

    • ben-t's avatar
      ben-t
      Frequent Visitor

      It generates without issue once i added in this line
      Thanks! 

      • GekkeHellie's avatar
        GekkeHellie
        Regular Visitor

        Hi ben-t,

         

        Could you share the full code that worked for you?

        I think I've tried every possible code with the above solution, but I still get an error.

         

        Thanks!

  • m_dekorte's avatar
    m_dekorte
    Resident Rockstar

    Hi ben-t 

    Its an invironment/ item access issue, here's a work around. Just assign the field value to a variable and bring that into your calculation.

     

    let n = [FREQUENCY] in List.Generate(() => [Next job],
    each Date.From(_) <= Date.From(Date.AddYears(Date.EndOfYear(DateTime.LocalNow()), 1)),
    each Date.AddMonths(_, n ))

     

    Ps. If this helps solve your query please mark this post as Solution, thanks!