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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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