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
awitt
Helper III
Helper III

SUMX / Date Range Question

I have a question I am trying to answer with multiple variables that is causing some challenges. 

 

I am wanting to sum the total orders only within a certain time frame for multiple customers. The challenge is that the date range is different per customer with frequet overlapping. For insance Customer 1 might have a date range I wish to evaluate of Jan 3 - Jan 17 and Customer 2 might have a date range of Jan 10 - Jan 24. These dates ranges per customer are identified in a separate table.

 

What is happening currently is that both customer's orders are being evaluated over the entire date range, Jan 3 - 24 for example, and not summing only the date range I wish to evaluate per customer.  The below image is how I would want the result to calculate. In reality there are thousands of customers and not just 2. 

 

awitt_1-1646759115733.png

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @awitt ,

 

Create a measure like below.

 

measure =
CALCULATE (
SUM ( 'table1'[sales] ),
FILTER (
ALLSELECTED ( 'table1' ),
'table1'[customer] = SELECTEDVALUE ( 'table2'[customer] )
&& 'table1'[date] >= SELECTEDVALUE ( 'table2'[start] )
&& 'table1'[date] <= SELECTEDVALUE ( 'table2'[end] )
)
)

 

Use 'table2'[customer], table2[start], 'table2'[end] and [measure] to create a visual.

 

Best Regards,

Jay

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @awitt ,

 

Create a measure like below.

 

measure =
CALCULATE (
SUM ( 'table1'[sales] ),
FILTER (
ALLSELECTED ( 'table1' ),
'table1'[customer] = SELECTEDVALUE ( 'table2'[customer] )
&& 'table1'[date] >= SELECTEDVALUE ( 'table2'[start] )
&& 'table1'[date] <= SELECTEDVALUE ( 'table2'[end] )
)
)

 

Use 'table2'[customer], table2[start], 'table2'[end] and [measure] to create a visual.

 

Best Regards,

Jay

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Expected result: =
CALCULATE (
    SUM ( Sales[Sales] ),
    FILTER (
        Sales,
        Sales[Date] >= RELATED ( Customer[Start Date] )
            && Sales[Date] <= RELATED ( Customer[End Date] )
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

The only thing preventing this to work, and it's my fault for not mentioning it, is that I cannot have a many to one relationship with the two tables and so the Related function will not work.

The customer table might have several different records per customer with different date ranges over the course of multiple years. 

Hi, 

I am not sure if I understood your feedback correctly, but please check the attached file.

The relationship has been deleted.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

So this measure does work, however when evaluating it in a table there seems to be some strangeness going on with the start date and filters. This table on the right has the data with no start date filter, and has many customers - in my case these customers are schools - filtered out. 

 

When I include a date filter for the start date like on the visual on the right, which is on the bottom of this message, everything gets included. Any idea why adding a filter would increase the amount of data being seen?

 

awitt_0-1646841852524.png

awitt_1-1646841959728.png

 

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.

Top Solution Authors