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
Mah_87
Frequent Visitor

Comparing Events this year Vs previous years with different date

Hi,
I have an issue calculating the comparison this year Vs previous years.
I want to have a page on which users can select events and get the result.
I want to compare the selected holiday with the same holiday last year. the issue is that holidays are not on the same date so the time intelligence functions not working
I got the correct result just when I filter my holiday table in the power query to have only one event! but when I want to expand to have all the events in the table then my measures do not work and give me the below error.

Mah_87_0-1674105969991.png

I used this measure:

*Holiday LY =
 VAR currentDate = SELECTEDVALUE('Date'[Date] )
           
VAR prevholiday =
    CALCULATE (
      VALUES( 'reference holidays_table'[Date] ),
        YEAR ( 'reference holidays_table'[date] )
            = YEAR ( currentDate ) - 1
    )
RETURN
    CALCULATE ( SUM ( Summary[Current]), 'Date'[Date] = prevholiday)



I think the problem is  VALUES( 'reference holidays_table'[Date] ) as it returns all the dates for each event and I need a way to only capture the selected date!
this is my data model

Mah_87_1-1674106372769.png

 


Thanks in advance

2 REPLIES 2
amitchandak
Super User
Super User

@Mah_87 , Make the join with date table single Directional. Mark date table as date table

 

and use measures like 

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),previousyear('Date'[Date]))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR('Date'[Date]))

 

//Only year vs Year, not a level below

This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))
diff = [This Year]-[Last Year ]
diff % = divide([This Year]-[Last Year ],[Last Year ])

 

Time Intelligence, Part of learn Power BI https://youtu.be/cN8AO3_vmlY?t=27510
Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

 

Thanks for your response
did not work! my date table is already marked as a date table but PBI does not allow me to make a single direction!
These calculations not worked. I want a slicer like this and when the user chooses each on it then the result shows for the last year based on the selected. but the dates for some of the holidays vary between years, it is not the same day last year for example Easter day!
As mentioned my measure works fine as long as I have only one holiday like Boxing day in my data set and by choosing each of the boxing days in 2019,2020,2021,2022 from my holiday table it works fine, but when I remove the filter in Power query to have the rest of the holiday like the below snippet then my measure not work!

Mah_87_1-1674165461400.png

Thanks

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.