Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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"), _))
And this works fine:
Date.AddMonths([invoices_start],_)
However this does not work:
List.Transform({0..[number_of_months]-1}, each Date.AddMonths([invoices_start],_))
I get the message:
Expression.Error: We cannot apply field access to the type Number.
What's the problem??? It's driving me crazy.
Solved! Go to Solution.
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.
Hi,
Can you try casting _ as number
something like this - List.Transform({1, 2}, each Date.AddMonths(Date.From("10/02/2017"), _ as number))
P
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.
It 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.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
81 | |
76 | |
61 | |
37 | |
33 |
User | Count |
---|---|
99 | |
56 | |
51 | |
42 | |
40 |