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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
naufal_msr
Frequent Visitor

Compare sales with different festive dates every year

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 !

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @naufal_msr ,

 

Firstly I suggest you to add an unrelated Holiday table with all holidays and dates you need in it. 

1.png

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:

2.png

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.

1.png

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.

 

View solution in original post

6 REPLIES 6
v-rzhou-msft
Community Support
Community Support

Hi @naufal_msr ,

 

Firstly I suggest you to add an unrelated Holiday table with all holidays and dates you need in it. 

1.png

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:

2.png

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.

1.png

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.

 

amitchandak
Super User
Super User

@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"))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

hi,

 

thank you for your help. However, Im having issue to highlight the YEAR column. Any idea why ?

naufal_msr_0-1640156596750.png

 

@naufal_msr , In filter inside all, Take only table name. When you take column name, it restricts it to that column

 

Filter(all(CalendarTable) ,

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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