Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I have a salesorder table with StartDate, EndDate and Interval in Power BI and I would like to create revenue records by PowerQuery. Revenue records should be created per salesorder, from the StartDate to the EndDate with an Interval of 1, 3 or 12 months. These records should have a RevenueDate and salesorderid (=GUID). The following Power Query M formula gives Expression.Error: We cannot apply field access to the type Date.
Details:
Value=01/12/2024
Key=EndDate
The first record of salesorder has 01/12/2024 as StartDate. Both StartDate and EndDate have the Date Type and I filtered out the salesorder records that have a blank StartDate or EndDate just te be sure. I think maybe it has something to do with trying to get the salesorder column values from the list correctly. But I can't figure out how to make it right.
How can I solve this?
let
Source = salesorder,
AddRevenueDates = Table.AddColumn(Source, "RevenueDates", each
List.Generate(
() => [StartDate], // Starting value
each _ <= [EndDate], // Create only when <= EndDate
each Date.AddMonths( _, [Interval] ) // Take steps of x months
)
),
ExpandRevenueDates = Table.ExpandListColumn(AddRevenueDates, "RevenueDates"),
RenameColumns = Table.RenameColumns(ExpandRevenueDates, {{"RevenueDates", "RevenueDate"}}),
SelectColumns = Table.SelectColumns(RenameColumns, {"RevenueDate", "salesorderid"})
in
SelectColumns
Solved! Go to Solution.
Hi @TimothyBohte ,
Thanks for Omid_Motamedise reply.
Based on your description, the problem may be in how the List.Generate function accesses the StartDate and EndDate fields. When using List.Generate, you need to make sure that these fields are referenced correctly in the context of each row. You can try the following code to see if it resolves the error
let
Source = salesorder,
AddRevenueDates = Table.AddColumn(Source, "RevenueDates", each
let
startDate = [StartDate],
endDate = [EndDate],
interval = [Interval]
in
List.Generate(
() => startDate,
each _ <= endDate,
each Date.AddMonths(_, interval)
)
),
ExpandRevenueDates = Table.ExpandListColumn(AddRevenueDates, "RevenueDates"),
RenameColumns = Table.RenameColumns(ExpandRevenueDates, {{"RevenueDates", "RevenueDate"}}),
SelectColumns = Table.SelectColumns(RenameColumns, {"RevenueDate", "salesorderid"})
in
SelectColumns
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @TimothyBohte ,
Thanks for Omid_Motamedise reply.
Based on your description, the problem may be in how the List.Generate function accesses the StartDate and EndDate fields. When using List.Generate, you need to make sure that these fields are referenced correctly in the context of each row. You can try the following code to see if it resolves the error
let
Source = salesorder,
AddRevenueDates = Table.AddColumn(Source, "RevenueDates", each
let
startDate = [StartDate],
endDate = [EndDate],
interval = [Interval]
in
List.Generate(
() => startDate,
each _ <= endDate,
each Date.AddMonths(_, interval)
)
),
ExpandRevenueDates = Table.ExpandListColumn(AddRevenueDates, "RevenueDates"),
RenameColumns = Table.RenameColumns(ExpandRevenueDates, {{"RevenueDates", "RevenueDate"}}),
SelectColumns = Table.SelectColumns(RenameColumns, {"RevenueDate", "salesorderid"})
in
SelectColumns
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
replace the part of formula by the below code
List.Generate(
() => [StartDate], // Starting value
(x)=> x<= [EndDate], // Create only when <= EndDate
(x)=> Date.AddMonths( x, [Interval] ) // Take steps of x months
)
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 |
---|---|
13 | |
13 | |
11 | |
8 | |
8 |
User | Count |
---|---|
17 | |
10 | |
7 | |
7 | |
7 |