Forum Discussion
mzrkwcz
Helper I
9 years agoGenerating a list of months problem
I need to generate a list of dates having: - [start_date] - [number_of_months] I tested that this works fine: List.Transform({0..[number_of_months]-1}, each Date.AddMonths(DateFrom("2017-05-05...
- 9 years ago
Out of my head (so not tested), I'm pretty sure this should work:
List.Transform({0..[number_of_months]-1}, (x) => Date.AddMonths([invoices_start],x))By using (x) => instead of each, you can refer to the list item (i.e. the number) within the Date.AddMonths function.
MarcelBeug
Community Champion
9 years agoOut of my head (so not tested), I'm pretty sure this should work:
List.Transform({0..[number_of_months]-1}, (x) => Date.AddMonths([invoices_start],x))
By using (x) => instead of each, you can refer to the list item (i.e. the number) within the Date.AddMonths function.
mzrkwcz
Helper I
9 years agoIt works! Thanks!
I have not seen (x) => f(x) in Power Query M Reference on MSDN, but probably I did not dig deep enough :-/
I still do not understand why solution with "each" works when I am increasing a constant date and does not work with the use of another field to deliver the date to be incremented.