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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
rwittmann08
Frequent Visitor

Year Over Year - Monday to Monday with Leap Year

Hello,

 

Our organization is trying to figure out a way to calculate year over year calculations, but to the actual day.  For example...

 

Monday, 2/17/2020 vs Monday, 2/18/2019

 

The added complexity is with leap year.  For example...

 

Sunday, 3/1/2020 vs Sunday, 3/3/2019

 

We are trying to calculate simple equations (Sum of Sales, Sum of Quantity, etc.) and would appreciate help in this equation.

 

Any help would be great!

1 ACCEPTED SOLUTION

@rwittmann08 

To me, the above solution seems like a measure only. It is created as a column.

 

Typically same weekday last year is 364 days behind, so you can also use (Example)

Week Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-364,Day))

 

Make sure you have Date table.

 

View solution in original post

8 REPLIES 8
v-frfei-msft
Community Support
Community Support

Hi @rwittmann08 ,

 

Here I created a date table as below firstly.

Table = 
ADDCOLUMNS (
    CALENDAR ( DATE ( 2019, 01, 01 ), DATE ( 2020, 12, 31 ) ),
    "Weeknum", WEEKNUM ( [Date], 2 ),
    "Weekday", WEEKDAY ( [Date], 2 ),
    "Year", YEAR ( [Date] )
)

 

After that, create a measure as below to work on it.

previous year = 
VAR maxyear =
    MAX ( 'Table'[Year] ) - 1
VAR weekd =
    MAX ( 'Table'[Weekday] )
VAR weekn =
    MAX ( 'Table'[Weeknum] )
RETURN
    CALCULATE (
        SUM ( 'Table'[value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Year] = maxyear
                && 'Table'[Weekday] = weekd
                && 'Table'[Weeknum] = weekn
        )
    )

Capture.PNG

 

For more details, please check the pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hi @v-frfei-msft,

 

That works!  Thank you!  I can confirm the day shifts happen as expected with this.  Monday to Monday. 

 

Is it possible to create a measure off of this so visualizations can be used.  Please see below...

 

BI Example Image.PNG

@rwittmann08 

To me, the above solution seems like a measure only. It is created as a column.

 

Typically same weekday last year is 364 days behind, so you can also use (Example)

Week Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-364,Day))

 

Make sure you have Date table.

 

Hi @amitchandak,

 

Thank you for sharing this as this is working perfectly!

 

Ryan 

 

 

Please mark the solution that worked for you.

Thank you for responding @v-frfei-msft! I'll try this out!

Pragati11
Super User
Super User

Hi @rwittmann08 ,

 

I think you can use SAMEPERIODLASTYEAR dax in your case.

https://docs.microsoft.com/en-us/dax/sameperiodlastyear-function-dax

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Spoiler
Hello @Pragati11,

Thank you for responding.  I have looked into this; however, it does the date equivalent to LY not the day equivalent.

Formula does: 2/18/2020 vs 2/18/2019

I need: 2/18/2020 vs 2/19/2019.  Once leap year occurs I will need... 3/1/2020 to 3/3/2019.


Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.