0 likes | 12 Views
Year on Year comparison by weekday in power BI<br><br>A Step by Step guide to avoid potential errors when using SAMEPERIODLASTYEAR and a simple solution to ensure you compare matching weekdays<br><br>https://www.selectdistinct.co.uk/2024/04/16/year-on-year-power-bi/<br><br>#PowerBI #SAMEPERIODLASTYEAR #DataViz
E N D
Comparing YEAR on YEAR in Power BI Power BI Tips and Timesavers https://www.bensound.com/ (energy) https://www.bensound.com/
Power BI has a built in function SAMEPERIODLASTYEARBut, it does not necessarily give you what you need, here we show an alternative to make sure year on year comparisons match by weekday
Why would you need to SAMEPERIODLASTYEAR does not take the day of the week into accountAnd this year is a leap year, so the dates are two days out of sync
The Simple Solution We will use a matching date from 364 days earlier for comparison. Then each weekday will always match even across a leap year
Use Case Example Data that varies between weekdays and weekends need to have sensible comparisons, here we can see website impression which drop at the weekends
Step by Step Solution The first thing we will do is show what happens when we use the same period last year functionWe create a measure to return the Impressions for the previous year using the SAMEPERIODLASTYEAR function Impressions LY = CALCULATE(sum('Sample GSC Data'[Impressions]), SAMEPERIODLASTYEAR('Sample GSC Data'[Date])) Then we can easily add the result into a simple table to see the result
Step by Step Solution At first glance this looks OKBut validation the data back to prior year we can that SAMEPERIODLASTYEAR is not working as we would like it toThe standout number for last year is the 13 showing against the 13th of April being compared to Saturday the 13th of April 2024Looking back at the 13th of April 2023 we can see it was a Thursday
Step 2 – Create a Measure to return the correct Year on Year comparison We know that if we compare to 364 days ago we will always match the weekday. So we create a filtered measure that does this Impressions LY2 = CALCULATE(sum('Sample GSC Data'[Impressions]), DATEADD('Sample GSC Data'[Date],-364,DAY)) We use the DATEADD function, with a minus 364 days value to match to the correct dates it now correctly aligns to the week day
If you need to have comparison of year on year performance where the data is by day, then you need to use this technique or similar Subscribe to our channel to see more tips and timesavers
For more Tips, Tricks and Timesavers, visit our websiteBusiness Analytics Blog – Select DistinctCredit: simon.harrison@selectdistinct.co.uk