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
Anonymous
Not applicable

Create a conditional sum using a date table

Hi

I am trying to create a dax measure, where if the date (taken from the date table) is between the start and end date then sum the cost.

I'm think i'm trying to combine too many steps in one. Is someone able to help with the query?

Thanks

 
CostStart DateEnd date
1001/01/202405/01/2024
2008/01/202409/01/2024
2010/01/202415/01/2024

 

Date table
01/01/2024
02/01/2024
03/01/2024
04/01/2024
05/01/2024
06/01/2024
07/01/2024
08/01/2024
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Your solution is great, bhanu_gautam. It worked like a charm! Here I have another idea in mind, and I would like to share it for reference.

I create two tables as you mentioned.

vyilongmsft_0-1724986185432.png

vyilongmsft_1-1724986205761.png

Then I create a calculated column and here is the DAX code.

Column = 
SUMX(
    'Table',
    IF(
        'Date'[Date] >= 'Table'[Start Date] && 'Date'[Date] <= 'Table'[End Date],
        'Table'[Cost],
        0
    )
)

vyilongmsft_2-1724986561434.png

 

 

 

Best Regards

Yilong Zhou

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 @Anonymous ,

Your solution is great, bhanu_gautam. It worked like a charm! Here I have another idea in mind, and I would like to share it for reference.

I create two tables as you mentioned.

vyilongmsft_0-1724986185432.png

vyilongmsft_1-1724986205761.png

Then I create a calculated column and here is the DAX code.

Column = 
SUMX(
    'Table',
    IF(
        'Date'[Date] >= 'Table'[Start Date] && 'Date'[Date] <= 'Table'[End Date],
        'Table'[Cost],
        0
    )
)

vyilongmsft_2-1724986561434.png

 

 

 

Best Regards

Yilong Zhou

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

bhanu_gautam
Super User
Super User

@Anonymous , You can try below DAX for this

 

DAX
TotalCost :=
VAR SelectedDate = SELECTEDVALUE('DateTable'[Date])
RETURN
SUMX(
FILTER(
'CostTable',
SelectedDate >= 'CostTable'[Start Date] && SelectedDate <= 'CostTable'[End Date]
),
'CostTable'[Cost]
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






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