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

Be 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

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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) ,

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.