Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join 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.

Reply
TimothyBohte
Frequent 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 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

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

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

Omid_Motamedise
Super User
Super User

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
	)  
If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.