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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ed7
Employee
Employee

Dax dateadd in measure doesn't work as expected

I have 2 measures: 

Cases as of today = Sum('!Data'[Cases])
Cases as 20 days ago = Calculate(Sum('!Data'[Cases]), DATEADD('Calendar'[Date].[Date],-20,DAY))
 
//My Data table has # of cases for each calendar date. Calendar table has a relation to the Data table.
 
In the visual I filter to last date, my expectation to see the current # of cases and # that was 20 days ago, BUT .. both numbers are the same.  
 
Any idea about what I'm doing wrong? 
Thank you so much.
 
PS: it was my stupid typo here: 'Calendar'[Date].[Date]. Thank you for helping me to catch it,
2 ACCEPTED SOLUTIONS
nandukrishnavs
Super User
Super User

@ed7 

Cases as of today = SUM('!Data'[Cases])
Cases as 20 days ago = 
var _lastdate= max(Calendar[Dates])
var _total=CALCULATE(SUM('!Data'[Cases]),DATESINPERIOD(Calendar[Dates],_lastdate,-20,DAY))
return _total

 

Capture.JPG

 



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

View solution in original post

Anonymous
Not applicable

Please do yourself a favour and create a proper Calendar. Do not ever rely on the automatic date hierarchy if you want to create correct formulas.

Please note that such syntax:

'Calendar'[Date].[Date]

is a sign you're not doing it right.

Best
D

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Please do yourself a favour and create a proper Calendar. Do not ever rely on the automatic date hierarchy if you want to create correct formulas.

Please note that such syntax:

'Calendar'[Date].[Date]

is a sign you're not doing it right.

Best
D

@Anonymous Could you please elaborate on creating proper Calendar, please?  I fixed my typo in formula, tried to use your code. Still doesn't work

Anonymous
Not applicable

Hi there.

Marco will explain to you all about Calendars:

https://www.sqlbi.com/tv/time-intelligence-in-microsoft-power-bi/

Best
D
nandukrishnavs
Super User
Super User

@ed7 

Cases as of today = SUM('!Data'[Cases])
Cases as 20 days ago = 
var _lastdate= max(Calendar[Dates])
var _total=CALCULATE(SUM('!Data'[Cases]),DATESINPERIOD(Calendar[Dates],_lastdate,-20,DAY))
return _total

 

Capture.JPG

 



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors