Forum Discussion

TimothyBohte's avatar
TimothyBohte
Frequent Visitor
2 years ago
Solved

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...
  • Anonymous's avatar
    Anonymous
    2 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 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