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

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

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. 

@bitbit , 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

amitchandak
Super User
Super User

@bitbit , 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-bd52912a5b...
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.

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.