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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

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

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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