March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
Im looking for ways to compare sales during festivities. What I've done so far is create a custom festive calendar and link to my calendar table. I guess the issue is currently on festivities that do not fall on the same date every year like Christmas / New Year. For example Chinese Lunar New Year falls on different date and Im not sure how to do in DAX. Purpose of me doing this is I wanna create a calculated column for Last Year Holiday Sales which ultimately i wanna compare the growth etc. If i do thisyearsales - PREVIOUSYEAR(sales) it will give me the same date of this year which is not accurate the date of last year's festivity. Not sure if this makes any sense but I appreciate any help I can get.
Thanks !
Solved! Go to Solution.
Hi @naufal_msr ,
Firstly I suggest you to add an unrelated Holiday table with all holidays and dates you need in it.
Then create a calendar table with holiday from this Holiday table.
Date =
ADDCOLUMNS (
CALENDARAUTO (),
"Holiday",
CALCULATE (
MAX ( 'Holiday Date'[Holiday] ),
FILTER ( 'Holiday Date', [Date] >= [Holiday Start] && [Date] <= [Holiday End] )
),
"YEAR", YEAR ( [Date] )
)
Relationship:
Measures:
Cur Year Sales =
VAR _SELECTHOLIDAY =
SELECTEDVALUE ( 'Holiday Date'[Holiday] )
VAR _SALES =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER ( 'Date', 'Date'[Holiday] = _SELECTHOLIDAY )
)
RETURN
_SALES
Previous Year Sales =
VAR _SELECTHOLIDAY =
SELECTEDVALUE ( 'Holiday Date'[Holiday] )
VAR _SALES =
CALCULATE (
SUM ( 'Table'[Sales] ),
PREVIOUSYEAR ( 'Date'[Date] ),
'Date'[Holiday] = _SELECTHOLIDAY
)
RETURN
_SALES
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @naufal_msr ,
Firstly I suggest you to add an unrelated Holiday table with all holidays and dates you need in it.
Then create a calendar table with holiday from this Holiday table.
Date =
ADDCOLUMNS (
CALENDARAUTO (),
"Holiday",
CALCULATE (
MAX ( 'Holiday Date'[Holiday] ),
FILTER ( 'Holiday Date', [Date] >= [Holiday Start] && [Date] <= [Holiday End] )
),
"YEAR", YEAR ( [Date] )
)
Relationship:
Measures:
Cur Year Sales =
VAR _SELECTHOLIDAY =
SELECTEDVALUE ( 'Holiday Date'[Holiday] )
VAR _SALES =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER ( 'Date', 'Date'[Holiday] = _SELECTHOLIDAY )
)
RETURN
_SALES
Previous Year Sales =
VAR _SELECTHOLIDAY =
SELECTEDVALUE ( 'Holiday Date'[Holiday] )
VAR _SALES =
CALCULATE (
SUM ( 'Table'[Sales] ),
PREVIOUSYEAR ( 'Date'[Date] ),
'Date'[Holiday] = _SELECTHOLIDAY
)
RETURN
_SALES
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@naufal_msr , You have to give the period a name of a number in the date calendar and then
example
This year = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[Name] = "New Year" ))
Last year = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year])-1 && 'Date'[Name] = "New Year"))
hi,
thank you for your help. However, Im having issue to highlight the YEAR column. Any idea why ?
@naufal_msr , In filter inside all, Take only table name. When you take column name, it restricts it to that column
Filter(all(CalendarTable) ,
Thank you for the help !
If I have many holidays to be included, does it mean I need to create a DAX for each of the holidays in order for me to display by Sales by Holiday ?
@naufal_msr , You can try like
Last year = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year])-1 && 'Date'[PH] = max('Date'[PH] ) ))
this will club holiday type , now if you have PH is the context you can compare YOY for that PH
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
127 | |
85 | |
69 | |
53 | |
44 |
User | Count |
---|---|
202 | |
106 | |
100 | |
64 | |
56 |