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

Last year week based on day name

Hi all!

 

I need help with a dax function for last year data. I am using this function to calculate, for example, the revenue.

 

Revenue =
var calc =
CALCULATE(
sum(table[revenue]);
USERELATIONSHIP('TableDates [Date]'[date];table[date])
)
return
IF(calculo = BLANK() ; 0; calculo)
 
Revenue last year =
CALCULATE(
[Revenue];
DATEADD('TableDates [Date]'[date]; -1; YEAR)
)
 
When I am drilling down from month to week, the information of week last year is not the same (by month and days is working perfectly). That's because the seven days of the week 201829 are not the same in 201929LY. How can I modify the fuction to get the same number?
Week_Dates.png
TableDates:
 
dates.PNG
 
Error in the graph:
 
week_overview.PNG
3 REPLIES 3
Anonymous
Not applicable

Hello @Anonymous,

 

Have you tried using the DATESYTD function?

 

Instead of DATEADD('TableDates [Date]'[date]; -1; YEAR), you can use:

 

DATESYTD ( 'TableDates [Date]'[Date] )

More info: https://docs.microsoft.com/en-us/dax/datesytd-function-dax

 

Also, your table naming ('TableDates [Date]') is quite confusing as it has square brackets which are normally used for column notation.

 

Hope this helps!

Alex

Anonymous
Not applicable

Thanks for your answer Alex,

 

In this case we have several dates table so we have this names in brackes to know which one we have to use, just a name.

I have seen that DATESYTD https://dax.guide/datesytd/ function will sum all the values in the year, but I need to compare year and year-1 in two lines., gettin the same value in 201829 tan 201929 - Previous year. I have uploaded the question with an example.

 


@Anonymous wrote:

Hello @Anonymous,

 

Have you tried using the DATESYTD function?

 

Instead of DATEADD('TableDates [Date]'[date]; -1; YEAR), you can use:

 

DATESYTD ( 'TableDates [Date]'[Date] )

More info: https://docs.microsoft.com/en-us/dax/datesytd-function-dax

 

Also, your table naming ('TableDates [Date]') is quite confusing as it has square brackets which are normally used for column notation.

 

Hope this helps!

Alex


 

Hey,

 

this article

https://www.daxpatterns.com/time-patterns/

will provide additional hints how to find the "exact" same timeframe in the past, of course one has to decide how leap years have to be handles.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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