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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
prasy
New Member

DAX Formula for LY MTD(using TOTALMTD and CALCULATE)

 

DAX  behavior for each formula is different.

 

I want to calculate Last Year MTD , By default without any slicer selection the function should take Today's date(Last Year) as end of date and calculate sum. If users choose any selection it should take that date as End of date(Last Year)

 

  1. LYMTD = TOTALMTD(SUM([Amount]),SAMEPERIODLASTYEAR(DATESMTD([BDate])))
  2. Previous Year MTD Total = CALCULATE([mTD Total],SAMEPERIODLASTYEAR([BDate])) 
  3. mTD Total = CALCULATE(sum([Amount]),DATESMTD([BDate]))
  4. PY MTDSALES = CALCULATE(SUM([Amount]), DATEADD(DATESMTD([BDate]),-1,YEAR))
  5. CACL PY MTD = CALCULATE(SUM([Amount]), DATESBETWEEN([BDate],  [FIRST DAY OF PRESENTMONTH LAST YEAR],  [Last DAY of PRESENTMONTH  Last Year] )) 
  6.  FIRST DAY OF PRESENTMONTH LAST YEAR = EDATE(FIRSTDATE(DATESMTD([BDate])),-12)
  7. Last DAY of PRESENTMONTH Last Year = EDATE(TODAY(),-12)

 

    • First Screen Shot is without any selections on slicer 1st.PNG
    • Second Screen shot with the 1st  date selected -  Previous Year MTD Total  is showing up correct2nd.PNG
    • Third Screen shot with 2nd  date selection – LYMTD and PY MTDSALES are showing correct calculated value(taking dates from Oct 1st to Oct 3rd of last year as 4th was not working day) , but Previous Year MTD Total  is blank because Last year Oct 4th was not a working day

3rd.PNG

 

 

Fourth Screen shot with 3rd Date selection – LYMTD and Previous Year MTD Total  are showing up correct with calculation from Oct 1st to Oct 3rd 2015  and PY MTDSALES is totally wrong/incorrect

4th.PNG

 

1 REPLY 1
mohamed901
Regular Visitor

I have 3 columns "Month" & "Achievement" & "Location" that I need to create 1 calculated column to get "Average Number" from "Achievement" column using all location but in every month separated 

The average should be like the table below but I can't get the number with DAX.

 

Kindly any advice 

 

MonthAchievement LocationAverage 
1/1/20178010185
1/1/20179010285
2/1/20172010340
2/1/20176010540

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors