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
BlueSky
Helper I
Helper I

Problems with Year to date comparisons

Hi,
 
I'm trying to do a simple year to date vs last year to date, however running into some difficulties.
My table shows year and week number.
 
For 2020 week 1, I expect the 'Last Year' coloum to show 215, it's blank.  Any ideas?
Capture.JPG
 
This Year = CALCULATE(
sum(MockUp[Observations])
,MockUp[WTD]=1
)

 

Last Year = CALCULATE([mSumDeathsYTDv2], DATEADD(MockUp[Date],-1,YEAR), ALL(MockUp[Year], MockUp[WTD], MockUp[Date] ))

 

 

 

Week NumYearDateObservationsWTD
1201901/01/2019 1
1201902/01/2019 1
1201903/01/2019 1
1201904/01/2019 1
1201905/01/2019 1
1201906/01/2019                    2151
2201907/01/2019 1
2201908/01/2019 1
2201909/01/2019 1
2201910/01/2019 1
2201911/01/2019 1
2201912/01/2019 1
2201913/01/20192801
1202001/01/2020 1
1202002/01/2020 1
1202003/01/2020 1
1202004/01/2020 1
1202005/01/20201891
2202006/01/2020 1
2202007/01/2020 1
2202008/01/2020 1
2202009/01/2020 1
2202010/01/2020 1
2202011/01/2020 1
2202012/01/20202751
1 ACCEPTED SOLUTION

The inbuilt time intelligence functions that you are using work on dates, not week numbers. So 3 Jan May be week 2 one year and week 1 the year after (for example). If you want to report on like for like week numbers, you need to write a custom time intelligence function.  Read my article here 

https://exceleratorbi.com.au/dax-time-intelligence-beginners/



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @BlueSky,

As MattAllington said, time intelligence functions not suitable for your scenario. I'd like to suggest you extract current 'year' and 'week num' as condition parameter to filter records:

Last Year =
VAR currYear =
    MAX ( MockUp[Year] )
RETURN
    CALCULATE (
        MAX ( MockUp[Observations] ),
        FILTER ( ALLSELECTED ( MockUp ), [Year] = currYear - 1 ),
        VALUES ( MockUp[Week Num] )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

The inbuilt time intelligence functions that you are using work on dates, not week numbers. So 3 Jan May be week 2 one year and week 1 the year after (for example). If you want to report on like for like week numbers, you need to write a custom time intelligence function.  Read my article here 

https://exceleratorbi.com.au/dax-time-intelligence-beginners/



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Thanks Matt, very well written blog post, helped a lot.

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.