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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

DAX help - calculate MTD, YTD and Full Year

I did not managed to create my table to show MTD, YTD and Full Year for comparative year(s).  Pls advise where did I go wrong.  File url:  https://1drv.ms/x/s!Aj1jIHqeNbLXkyDkyO0tSLgHeFi9?e=a6Dg4N  

3 REPLIES 3
Anonymous
Not applicable

Hi, amitchandak.  Recommended solution does not work.

 

I have separate datasets for 2020 and 2021 which capture month by month sales volume, net sales and gross margin by product.  These 2 datasets are linked to an auto generated date table "Calendar".  The data table is linked to a separate table "Month" listing the 12 months (used as slicer).

Measures created in the sales datasets as follows:

2020 dataset:

MTD Sales = CALCULATE(SUM(2020[Amount]),DATESMTD('Calendar'[Date]))

YTD Sales = CALCULATE(SUM(2020[Amount]),DATESYTD('Calendar'[Date]))

Total Year Sales = CALCULATE(SUM(2020[Amount]),ALL('Month'[Month]))

 

Similar measures are created in the 2021 sales dataset.

 

Outcome: pivot table shows 2021 MTD, YTD and Total Year data correctly, but no data reflected in 2020 columns.

 

Pls advise solution. 

@Anonymous , if you table 2020 has dates of 2020, then you have to create last year/year behind measure for YTD/MTD etc

 

as same date table is applied to both tables, so  current year is 2021

 

I have give example in my last post

 

 

 

Refer if needed

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

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

@Anonymous , That excel, what measures you have tried

 

example with date table

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))

last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5bd4
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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