I have a fact table called [Sales], and in it, I have daily sales for calendar years 2011, 2012, and 2013 described with two columns: [Date] and [Revenue].
I also have set up a date table called [DimDate] where there is a contiguous set of dates that cover the years in question on a daily basis in a column called [DateKey]. Actually, my [DimDate] table goes all the way from 1975 through 2020. I have established a relationship between [Sales] and [DimDate] tables through the DimDate[DateKey] and Sales[Date] columns.
In any case, I have the time honored problem of comparing one year's sales on a daily basis and on a monthly basis. I have two methods that seem to work, and I would like to get some pros and cons of each approach (since I am not able to see what advantages one approach has over the other).
To begin, I define a measure on the [Sales] table called [Sum of Revenue]:=SUM([Revenue]).
Here are my two approaches to defining a measure called [Sales Amount Last Year] on the [Sales] table.
Approach 1: Define [Sales Amount Last Year]:=CALCULATE([Sum of Revenue], SAMEPERIODLASTYEAR(DimDate[DateKey])).
Approach 2: Define [Sales Amount Last Year]:=CALCULATE([Sum of Revenue],DATEADD(DimDate[DateKey], -1,YEAR)).
Approach 1 uses the SAMEPERIODLASTYEAR function, and Approach 2 uses the DATEADD function.
Has anyone encountered a situation where they preferred to use one over the other, and can you please share why you chose the one that you did?
I also have set up a date table called [DimDate] where there is a contiguous set of dates that cover the years in question on a daily basis in a column called [DateKey]. Actually, my [DimDate] table goes all the way from 1975 through 2020. I have established a relationship between [Sales] and [DimDate] tables through the DimDate[DateKey] and Sales[Date] columns.
In any case, I have the time honored problem of comparing one year's sales on a daily basis and on a monthly basis. I have two methods that seem to work, and I would like to get some pros and cons of each approach (since I am not able to see what advantages one approach has over the other).
To begin, I define a measure on the [Sales] table called [Sum of Revenue]:=SUM([Revenue]).
Here are my two approaches to defining a measure called [Sales Amount Last Year] on the [Sales] table.
Approach 1: Define [Sales Amount Last Year]:=CALCULATE([Sum of Revenue], SAMEPERIODLASTYEAR(DimDate[DateKey])).
Approach 2: Define [Sales Amount Last Year]:=CALCULATE([Sum of Revenue],DATEADD(DimDate[DateKey], -1,YEAR)).
Approach 1 uses the SAMEPERIODLASTYEAR function, and Approach 2 uses the DATEADD function.
Has anyone encountered a situation where they preferred to use one over the other, and can you please share why you chose the one that you did?