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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
mansi_luthra12
New Member

Calculate sum based on start and end date

Hi All, 

I need to calculate the sum of the amount based on the start and end date for each month.
For example: In the below data TotalAmountPerMonth for Jan is 600 and For Feb it is only adding the active project (those whose end date is in Feb or after Feb). Hence the total amount for Feb is 700(100+200+400). 
If I use TotalYTD it accumulates all the costs from the previous month and doesn't filter the end date 

mansi_luthra12_0-1696842259080.png

 

Thanks and Regards, 

Mansi 

 

1 ACCEPTED SOLUTION

Hi, @mansi_luthra12 

 

Add a year column to the date table and add a year filter to the formula.

vzhangti_0-1697074278037.png

Measure = 
CALCULATE ( SUM ( 'Table'[Value] ),
    FILTER ( ALL ( 'Table' ),
        MONTH ( [StartDateScope] ) <= SELECTEDVALUE ( 'Date'[Month] )
            && MONTH ( [EndDateScope] ) >= SELECTEDVALUE ( 'Date'[Month] )
            &&YEAR([StartDateScope])=SELECTEDVALUE('Date'[Year])
    )
)

vzhangti_1-1697074308048.png

If you do not get the results you expect, please provide more detailed data.

 

Best Regards,

Community Support Team _Charlotte

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

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @mansi_luthra12 

 

You can try the following methods.
Date table:

vzhangti_0-1697018000005.png

Measure = 
CALCULATE ( SUM ( 'Table'[Value] ),
    FILTER ( ALL ( 'Table' ),
        MONTH ( [StartDateScope] ) <= SELECTEDVALUE ( 'Date'[Month] )
            && MONTH ( [EndDateScope] ) >= SELECTEDVALUE ( 'Date'[Month] )
    )
)

vzhangti_1-1697018070416.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Hi, 
Thanks for the reply the solution is perfectly fine if only one year is present. I have records for multiple years - from the calendar table even if I put a slicer on year it doesn't split the amount. 
for Example : if Jan 2023 was 100 and 2024 Jan is 200 then irrespective of which year is selected the calculation shows 300. 

Hi, @mansi_luthra12 

 

Add a year column to the date table and add a year filter to the formula.

vzhangti_0-1697074278037.png

Measure = 
CALCULATE ( SUM ( 'Table'[Value] ),
    FILTER ( ALL ( 'Table' ),
        MONTH ( [StartDateScope] ) <= SELECTEDVALUE ( 'Date'[Month] )
            && MONTH ( [EndDateScope] ) >= SELECTEDVALUE ( 'Date'[Month] )
            &&YEAR([StartDateScope])=SELECTEDVALUE('Date'[Year])
    )
)

vzhangti_1-1697074308048.png

If you do not get the results you expect, please provide more detailed data.

 

Best Regards,

Community Support Team _Charlotte

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

rubayatyasmin
Super User
Super User

Hi, @mansi_luthra12 

 

here is the example DAX that you can use based on your description. 

 

TotalAmountPerMonth =
SUMX(
FILTER(
ALL('Table'),
'Table'[StartDate] <= ENDOFMONTH('Date'[Date]) &&
(ISBLANK('Table'[EndDate]) || 'Table'[EndDate] >= STARTOFMONTH('Date'[Date]))
),
'Table'[Amount]
)

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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