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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Stemar_Aubert
Resolver I
Resolver I

Issue when using DATESYTD to calculate YTD YoY.

Hello,

 

I have a fact table with units and linked to a general time table.

 

My issue is when using DATESYTD, I want to obtain the following result:

 

This is the desired output.This is the desired output.

(For this, I used filters on the visual)

 

For this, I have used the following formula:

 

UNITS YTD 18=
CALCULATE (
SUM ( 'Actual'[UNITS] ),
SAMEPERIODLASTYEAR ( DATESYTD ( 'Time'[Dates] ) )
)
UNITS YTD 19=
CALCULATE (
    SUM ( 'Actual'[UNITS] ),
    DATESYTD ( 'Time'[Dates] ) 
)

 

 

The issue is that my data looks like this :

 

JAN 201812
......
DEC 20189
JAN 20193
OCT 20195

 

As you can see, I have months in 2018 that aren't present in 2019. So when I use my measures, DAX keeps calculating data for months when I don't want it to. The output is this:

 

V0i0Hu7

 

How can I modify my measures so YTD stops calculating data for months that aren't available in 2019 ?

I posted earlier a solution to this, but actually the formula stopped performing runnings total and gave out monthly total instead.

 

Thanks !

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

If you take a slicer and select then it will limit the value of YTD

Or try to limit like

Last YTD Sales = 
var _maxMonth = month(maxx(Sales,Sales[sales_date]))
CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year)), month(Date[date])<=_maxMonth)

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

If you take a slicer and select then it will limit the value of YTD

Or try to limit like

Last YTD Sales = 
var _maxMonth = month(maxx(Sales,Sales[sales_date]))
CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year)), month(Date[date])<=_maxMonth)

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak Thank you so much.

I've tried so many variations of this, the solution was to use MAXX and not simply MAX !

 

 

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.