I've got a date measure that works with some operators but not others. Perhaps someone can tell me what I'm doing wrong in formatting? I get an error that the date measure is a text measure and DAX cannot compare text and dates, but only for certain operations.
I've got an inflation formula that I want to apply to future months in a forecast plant operation. However, I only want to apply it after production starts (e.g. April 2019) rather than when the project (and calendar table) starts (e.g. August 2018). So for months prior to May 2019 the index would be 1, then it increases according to the inflation rate entered by the user.
The user enters the Production Start Date on the spreadsheet in a table with multiple default values for the model. PowerQuery pulls the table into the model with the column as a text value, and I use this formula to obtain the measure.
The measure I want to create is
But I get the error on the first IF clause. However, if I use
DATEDIFF([Production Start Date], MAX(Calendar[Date], MONTH)
DAX will recognize [Production Start Date] as a date. I can't use DATEDIFF in my first IF clause however since it can return negative values when the calendar dates in the pivot table are earlier than the start of production.
The Calendar[Date] field is generated in PowerQuery with a data type of Date, and it shows as a Date in the data model as well.
Multiplying [Production Start Date] * 1 will allow it to work in the Inflation Measure, but I'd like to get the measure to the correct type so I don't have to remember the workaround.
I've got an inflation formula that I want to apply to future months in a forecast plant operation. However, I only want to apply it after production starts (e.g. April 2019) rather than when the project (and calendar table) starts (e.g. August 2018). So for months prior to May 2019 the index would be 1, then it increases according to the inflation rate entered by the user.
The user enters the Production Start Date on the spreadsheet in a table with multiple default values for the model. PowerQuery pulls the table into the model with the column as a text value, and I use this formula to obtain the measure.
Code:
Production Start Date:=FORMAT (
CALCULATE (
MAX ( tblDefaults[Value] ),
tblDefaults[Item] = "Production Starts"
),
"Short Date"
)
The measure I want to create is
Code:
Inflation Index :=
IF (
MAX ( 'Calendar'[Date] ) <= [Production Start Date],
1,
CALCULATE (
POWER ( 1 + ( [Default Inflation Rate] / 12 ), [Months from Start] ),
FILTER ( 'Calendar', 'Calendar'[Date] <= MAX ( 'Calendar'[Date] ) )
)
)
But I get the error on the first IF clause. However, if I use
DATEDIFF([Production Start Date], MAX(Calendar[Date], MONTH)
DAX will recognize [Production Start Date] as a date. I can't use DATEDIFF in my first IF clause however since it can return negative values when the calendar dates in the pivot table are earlier than the start of production.
The Calendar[Date] field is generated in PowerQuery with a data type of Date, and it shows as a Date in the data model as well.
Multiplying [Production Start Date] * 1 will allow it to work in the Inflation Measure, but I'd like to get the measure to the correct type so I don't have to remember the workaround.