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
tutuk28
Helper IV
Helper IV

Compare Date Range with Previous Year Equivalent:

Hi everyone!

 

I have a slicer where I can select a range of dates and I need to compare with the equivalent days of the previous year selected.

Example:
If I select the date range from 10/20/2020 (Tuesday) to 10/28/2020 (Wednesday) it should compare with the values from 10/22/2019 (Tuesday) to 10/30/2019 (Wednesday).

 

Currently I have a measure that works but it compares me only one day:

CALCULATE (
    SELECTEDMEASURE (),
    FILTER (
        ALL ( 'Dim_Date' ),
        'Dim_Date'[Year]
            = MAX ( 'Dim_Date'[Year] ) - 1
            && 'Dim_Date'[Week of Year]
                = MAX ( 'Dim_Date'[Week of Year] )
            && 'Dim_Date'[Day of Week]
                = MAX ( 'Dim_Date'[Day of Week] )
    )
)

 

Thanks !

Regards!

1 ACCEPTED SOLUTION

@tutuk28 , I think you are looking for data 364 days behind

 

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

View solution in original post

6 REPLIES 6
tex628
Community Champion
Community Champion

Try this,

CALCULATE (
    SELECTEDMEASURE (),
    FILTER (
        ALL ( 'Dim_Date' ),
               'Dim_Date'[Year]
                <= MAX ( 'Dim_Date'[Year] ) - 1
            && 'Dim_Date'[Week of Year]
                <= MAX ( 'Dim_Date'[Week of Year] )
            && 'Dim_Date'[Day of Week]
                <= MAX ( 'Dim_Date'[Day of Week] )
            && 'Dim_Date'[Year]
                >= MIN ( 'Dim_Date'[Year] ) - 1
            && 'Dim_Date'[Week of Year]
                >= MIN ( 'Dim_Date'[Week of Year] )
            && 'Dim_Date'[Day of Week]
                >= MIN ( 'Dim_Date'[Day of Week] )
    )
)

Connect on LinkedIn
TomMartens
Super User
Super User

THIS post is not helpful, as I did not read the question properly, I'm sorry for the confusion.

Hey @tutuk28 ,

 

I'm wondering why you are not using the DAX function

SAMEPERIODLASTYEAR (https://dax.guide/sameperiodlastyear/#)

 

Maybe I miss something.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi @TomMartens,

 

I don't use the SAMEPERIODLASTYEAR function because it compares me to the same days, for example 10/20/2020 to 10/28/2020 vs 10/20/2019 to 10/28/2019 but I don't need that.

In my case, I need to be equivalent days as I mentioned in the example.

Thanks!

@tutuk28 , I think you are looking for data 364 days behind

 

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

Hi, if you have your date table you might be able to use time intelligence. The function you need is 

EDIT: I have just seen the 2019. It's -363 or -364 days to take it.

 

DATEADD(Date[Datecolumn], -364, DAY)

 

 

You can build a measure with CALCULATE and that as filter expresion to get the following 2 days for each date in the range. You will be able to compare it with that filter expresion.

Hope that helps 


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Hi @ibarrau !

In this case the problem is that if I select the year 2019 the difference with the year 2018 is 1 day, for example:
Tuesday 12/17/2019 the equivalent day of the previous year is Tuesday 12/18/2018.

Thanks!!

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.