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
M22
New Member

MTD and MTD LY against selected week value from drop down

I am trying to get the MTD last year against week 

i have Week End dates in my Drop down (single selection )

M22_0-1679473070325.png

i am calculatin MTD using following dask which is returning correct values (2 week of Mar-23)

MTD UNITS = TOTALMTD(sum('Table A'[Value Sales per Week]),'Table A'[Week End Date])
What will be the MTD last Year againt single selection drop down i tried many dax which are available online but they give me wrong answers. for exp i am selecting 2 weeks of 23 the result should b first 2 week of mar 22.
 
 
1 ACCEPTED SOLUTION
M22
New Member

Well i am done with DAX finally

MTD1 LY =
VAR CurrentMonth =
    MAX ( 'date[Date])
VAR LastYear =
    YEAR ( CurrentMonth ) - 1
VAR days = DAY(MAX('date[Date])+1)
VAR LastYearStartDate =
    DATE ( LastYear, MONTH ( CurrentMonth ), 1 )
VAR LastYearEndDate =
   DATE ( LastYear, MONTH ( CurrentMonth ), days )
VAR LastYearMTDStartDate =
    IF ( LastYearStartDate > DATE ( LastYear, 1, 1 ), LastYearStartDate, DATE ( LastYear - 1, 12, 1 ) )

RETURN
 CALCULATE (
        SUM('[ Value Sales]),
        DATESBETWEEN ( 'date[Date], LastYearMTDStartDate, LastYearEndDate )
    )

View solution in original post

1 REPLY 1
M22
New Member

Well i am done with DAX finally

MTD1 LY =
VAR CurrentMonth =
    MAX ( 'date[Date])
VAR LastYear =
    YEAR ( CurrentMonth ) - 1
VAR days = DAY(MAX('date[Date])+1)
VAR LastYearStartDate =
    DATE ( LastYear, MONTH ( CurrentMonth ), 1 )
VAR LastYearEndDate =
   DATE ( LastYear, MONTH ( CurrentMonth ), days )
VAR LastYearMTDStartDate =
    IF ( LastYearStartDate > DATE ( LastYear, 1, 1 ), LastYearStartDate, DATE ( LastYear - 1, 12, 1 ) )

RETURN
 CALCULATE (
        SUM('[ Value Sales]),
        DATESBETWEEN ( 'date[Date], LastYearMTDStartDate, LastYearEndDate )
    )

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.