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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
OCBB_SFAFPandA
Resolver I
Resolver I

How to calculate WTD, MTD, and YTD, along with Last year's

Hello,

 

I have a date table and followed this instrucional video to create a Week-to-date, Month-to-date and Year-to-date

How to calculate Year-To-Date, Quarter-To-Date, Month-To-Date in Power BI // Power BI Guide 2021 - S... 

 

When I used this measures, my Last year same week to date measures don't show with this. 

 

I am trying to create something like this

 

 WTDWTDMTDMTDYTDYTD
 TYLYTYLYTYLY
Sales10090400350900850

 

When I use WTD, MTD, YTD date filters, my Last year measures go away

 WTDWTDMTDMTDYTDYTD
 TYLYTYLYTYLY
Sales100 400 900 

 

 

Not sure how I would move forward. Should I try to create a calculation group with this year's WTD/MTD/YTD and last year's WTD/MTD/YTD. I think it's harder since I am not able to use "Same period last year", since I work in retail and need to match up the week numbers. 

2 REPLIES 2
daXtreme
Solution Sage
Solution Sage

// Assuming you've got a proper calendar
// that's been marked as such... The Year
// field I use in the code might be a
// year field that's not the true year but
// a modified field that's aligned with the
// weeks. That's because weeks don't go equally
// into years and you might have artificial
// years that are aligned to the weeks. So, please
// bear this in mind when you try to adjust this
// code.

[WTD LY] =
var LastVisibleDay = LASTDATE( Dates[Date] )
var LastVisibleWeekNumber = 
    CALCULATE(
        SELECTEDVALUE( Dates[WeekNumberInYear] ),
        LastVisibleDay
    )
var VisibleYear =
    CALCULATE(
        SELECTEDVALUE( Dates[Year] ),
        LastVisibleDay
    )
var DayNumberInWeek_ = 
    CALCULATE( 
        SELECTEDVALUE( Dates[DayNumberInWeek] ),
        LastVisibleDay
    )
var Result = 
    CALCULATE(
        [your measure],
        // Move back 1 year
        Dates[Year] = VisibleYear - 1,
        // Stay on the same week number
        Dates[WeekNumberInYear] = LastVisibleWeekNumber,
        // This condition will grab all days in the
        // week up to and including DayNumberInWeek_
        // just the way it should be to obtain WTD
        Dates[DayNumberInWeek] <= DayNumberInWeek_,
        // This will remove any filters from Dates
        // and you need this since there are no filters
        // here that operate directly on Dates
        REMOVEFILTERS( Dates )
    )
return
    Result

The other measures can be obtained in a very similar way with some obvious changes.

amitchandak
Super User
Super User

@OCBB_SFAFPandA , You need to use the calculation group for that

I have shown few samples here

Calculation Groups- Measure Slicer, Measure Header Grouping, Measure to dimension conversion. Complex Table display : https://youtu.be/qMNv67P8Go0

 

For Time intellignece

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA
Power BI — Qtr on Qtr with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-qtd-questions-time-intelligence-2-5-d842063da839
https://www.youtube.com/watch?v=8-TlVx7P0A0
Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA
Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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