Previous month to date DAX syntax

lochem

New Member
Joined
Jun 14, 2010
Messages
28
Hi all,

I am trying to build a formula to compare MonthToDate (MTD) and Last month todate (LMTD) values. MTD is easy enough, however its the last month's calculation that i cannot get.
If today is 14-March, and my KPI ("myExpression") for the month to-date is currently at, say 250, I want to compare this value with the same measurement that is calculated for the same date range of February, from 1-Feb to 14-Feb.

However i am running into errors with my logic...

I am looking for something similar to below:

Code:
LastMTD:=CALCULATE([myExpression], DATESBETWEEN([Date_Column],start_date<start_date>,end_date<last_date>))

for start_Date <start_date>and end_date <end_date>i am using the following:

Code:
FirstDateLM:=FIRSTDATE(dateadd(datesmtd(OpsCalendar[Date]),-1,month))

and

LastDateLM:=LASTDATE(DATEADD(DATESMTD(OpsCalendar[Date]),-1,MONTH))

two undesirable things are happening:
1. in my calendar, the date column ends at 31 dec 2016. my firstdateLM and lastdateLM fields are returning Nov 1 and Nov 30 2016, instead of actual last month first day and actual 30 days ago, etc.

2. i am getting an error in my LastMTD formula as follows: "A Table of multiple values was supplied where a single value was expected"
im guessing this has something to do with first and last dates in the DATESBETWEEN function, but i cannot be certain.

Please help?</end_date></start_date></last_date></start_date>
 
Last edited:
Clarifying, the concern would be "the fact table had nothing for Feb 12". Or *any* other day. time intelligence functions in dax must have a row for EVERY day... which is why there are typically built off a separate calendar table.

interesting....in that case, there are definitely days that do not appear at all in the fact table.

however, i checked the returned value from the formula using the 'local' date column and it actually returns the correct value, no problems.
it was only when i referenced the calendar table 'date' that returned a blank value.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,224,081
Messages
6,176,259
Members
452,717
Latest member
victorski

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top