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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

DAX formula to calculate YTD value starting with last calendar month

Hey everyone,

 

I'm trying to find a way to calculate the sum of a value for the year to date, starting with the last complete month.

 

For example, we are now in June so I would want a sum of this value for January 1st 2019 - May 31st 2019. In July I would want January 1st 2019 - June 30th 2019, etc.

 

I'm thinking it must be something like the following, but I'm struggling with getting it to work:

 

TOTALYTD(SUM(Table1[Column1]),DATEADD(DateDim[DateKey],-1,MONTH))
 
Any ideas?
Thanks!!
1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

You can do something like below

Measure = 
VAR todaysDate = TODAY()
VAR PreviousMonthStart = DATE( YEAR( todaysDate ), MONTH ( todaysDate ), 1 )  
RETURN 
CALCULATE(
    [Sales],
    DATESYTD( 'Calendar'[Date] ),
    KEEPFILTERS( 'Calendar'[Date] < PreviousMonthStart )
)

Regards,
Mariusz

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
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

You can do something like below

Measure = 
VAR todaysDate = TODAY()
VAR PreviousMonthStart = DATE( YEAR( todaysDate ), MONTH ( todaysDate ), 1 )  
RETURN 
CALCULATE(
    [Sales],
    DATESYTD( 'Calendar'[Date] ),
    KEEPFILTERS( 'Calendar'[Date] < PreviousMonthStart )
)

Regards,
Mariusz

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

Anonymous
Not applicable

Wow, I wasn't even close. Thank you for your help!!

The only strange thing I am still seeing is that when I pull this into a visual to test it, I see values for every single date in 2019 up to December 31st. The dates in my fact table don't go past June. Any idea why it is doing this even when this DAX formula is specifying dates prior to the first of the month?

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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