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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mafaber
Helper II
Helper II

Summing values in a column between two dates in Power Query

Hi,

 

I have a table with a demand plan per product per week and with a certain range in days per product telling how long into the future I need to consider the demand. What I would like to do is to calculate in a column a kind of rolling demand per product per week:

Table:

ProductRange of Coverage in daysWeekWeek start dateDemand end date (start date+RoC)Weekly DemandRolling Demand
aaa14012021.10.04.2021.10.18.10(w01+w02) = 25
aaa14022021.10.11.2021.10.25.1540
aaa14032021.10.18.2021.11.01.2530
aaa14042021.10.25.2021.11.08.55 + w05
bbb21012021.10.04.2021.10.18.100(w01+w02+w03) = 550
bbb21022021.10.11.2021.10.25.200600
bbb21032021.10.18.2021.11.01.250400 + w05
bbb21042021.10.25.2021.11.08.150150 + w05 + w06

 

Demand end date is calculated based on range of coverage of the specific product and the start date of the week, the calculation what I am looking for is the Rolling Demand. (the numbers only of course, text is just explanation)

 

So basically I need the sum of a value column where the week start date is between week start date and demand end date, and I have to calculate it in Power Query (Power BI Dataflow), not in DAX.

 

Thank you for any help!

1 ACCEPTED SOLUTION
mafaber
Helper II
Helper II

I solved it myself using a custom function.

 

  #"Grouped rows 1" = Table.Group(#"Replaced value", {"material_no"}, {{"data"each _, type nullable table}}),
  // Function to calculate running totals
  RunFunction = (RunTable as tableas table =>
    let
    #"Added index" = Table.AddIndexColumn(RunTable, "index"01type number),
    #"Added custom" = Table.AddColumn(#"Added index", "demand_running_sum"each List.Sum(List.Range(#"Added index"[value_of_week], [index], [range_of_coverage_weeks])))
in
    #"Added custom",
  // Call the function
  RunTotals = Table.TransformColumns(#"Grouped rows 1", {"data"each RunFunction(_)})
 
where the custom column calculates the demand starting from that row (index starting from 0) and as long as needed per material (range of coverage in weeks)
 

View solution in original post

1 REPLY 1
mafaber
Helper II
Helper II

I solved it myself using a custom function.

 

  #"Grouped rows 1" = Table.Group(#"Replaced value", {"material_no"}, {{"data"each _, type nullable table}}),
  // Function to calculate running totals
  RunFunction = (RunTable as tableas table =>
    let
    #"Added index" = Table.AddIndexColumn(RunTable, "index"01type number),
    #"Added custom" = Table.AddColumn(#"Added index", "demand_running_sum"each List.Sum(List.Range(#"Added index"[value_of_week], [index], [range_of_coverage_weeks])))
in
    #"Added custom",
  // Call the function
  RunTotals = Table.TransformColumns(#"Grouped rows 1", {"data"each RunFunction(_)})
 
where the custom column calculates the demand starting from that row (index starting from 0) and as long as needed per material (range of coverage in weeks)
 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors