Forum Discussion
TimothyBohte
2 years agoFrequent Visitor
Create revenue records from salesorder
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 StartDa...
- Anonymous2 years ago
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 errorlet 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 SelectColumnsBest regards,
Albert HeIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Omid_Motamedise
Super User
2 years agoreplace 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
)