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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.