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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
SzymonKl
Helper I
Helper I

undefinedHelp Needed: Summing Quantities Over a Date Range in Power BI

Hi Power BI Community,

I'm working on a report that requires summing quantities over a specified date range for each supplier. Here are the details:

Tables Involved:

  • SUPPLIERS: Contains information about suppliers.
  • SUPPLIER_TRANSFER_REQUESTS: Contains transfer data.
  • DEHIRE_LOGS: Contains dehire data.
  • DWELL_TIMES: Contains the allowance days.
  • CALENDAR: Contains calendar dates.
  • DAILY_BALANCE: Contains daily balance quantities.

Objective: For each supplier, I need to calculate the total quantity from the DEHIRE_LOGS table for a range of dates defined by the selected date in the slicer minus the allowance days from the DWELL_TIMES table.

Example: If the selected date in the slicer is 17/06/2024 and the allowance is 8 days, the date range should be from 09/06/2024 to 17/06/2024. The measure should sum the QUANTITY from the DEHIRE_LOGS table for this date range.

Steps Taken:

  1. Created a measure to calculate the start date:

    StartDateCheck = VAR SelectedDate = MAX(CALENDAR[Date]) VAR Allowance = MAX(DWELL_TIMES[ALLOWANCE]) RETURN SelectedDate - Allowance
  2. Created a measure to sum the quantities over the date range:

    TotalDehireQuantity = VAR SelectedDate = MAX(CALENDAR[Date]) VAR Allowance = MAX(DWELL_TIMES[ALLOWANCE]) VAR StartDate = SelectedDate - Allowance RETURN CALCULATE( SUM(DEHIRE_LOGS[QUANTITY]), FILTER( ALL(DEHIRE_LOGS), DEHIRE_LOGS[DEHIRED_AT] >= StartDate && DEHIRE_LOGS[DEHIRED_AT] <= SelectedDate ) )

Issue: Despite the steps above, the measure only shows the QUANTITY for the selected date, not the sum over the specified date range.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @SzymonKl 

 

I made some changes to your code:

 

 

Measure = 
var selectDate = SELECTEDVALUE('Calendar'[Date])
var Allowance = MAX('Dwell_Times'[Allowance])
var startDate = selectDate - Allowance
RETURN 
CALCULATE(
    SUM('Dehire_logs'[Quantity]),
    FILTER(
        ALLSELECTED('Dehire_logs'[Dehired_AT]),
        'Dehire_logs'[Dehired_AT] >= startDate
        &&
       'Dehire_logs'[Dehired_AT] <= selectDate
    )
)

 

 

vnuocmsft_0-1719367221778.png

 

vnuocmsft_1-1719367239285.png

 

      vnuocmsft_3-1719367269812.png

 

 

If you still have problems, it is best to provide the pbix file and be careful to delete sensitive data.

 

Regards,

Nono Chen

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

1 REPLY 1
Anonymous
Not applicable

Hi @SzymonKl 

 

I made some changes to your code:

 

 

Measure = 
var selectDate = SELECTEDVALUE('Calendar'[Date])
var Allowance = MAX('Dwell_Times'[Allowance])
var startDate = selectDate - Allowance
RETURN 
CALCULATE(
    SUM('Dehire_logs'[Quantity]),
    FILTER(
        ALLSELECTED('Dehire_logs'[Dehired_AT]),
        'Dehire_logs'[Dehired_AT] >= startDate
        &&
       'Dehire_logs'[Dehired_AT] <= selectDate
    )
)

 

 

vnuocmsft_0-1719367221778.png

 

vnuocmsft_1-1719367239285.png

 

      vnuocmsft_3-1719367269812.png

 

 

If you still have problems, it is best to provide the pbix file and be careful to delete sensitive data.

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.