PowerBI - DateAdd with max

Viewed 3104

I'm trying to add days in the date field but I always have the same error, my field "event_date" is date. I don't know what's wrong

Error

enter image description here

userActive =
var datamaxx = CONVERT (CALCULATE (max (table1 [event_date])), DATETIME)
var dad = DATEADD (DATE (YEAR (datamaxx), MONTH (datamaxx), DAY ((datamaxx))), 1, DAY)

or

userActive =
var datamaxx = CONVERT (CALCULATE (max (table1 [event_date])), DATETIME)
var dad = DATEADD (datamaxx, 1, DAY)
2 Answers

Are you trying to create a measure or a calculated column?

I simplified the below by removing the CALCULATE and also adding in the RETURN statement, you must RETURN a value when you have a multi-statement DAX formula.

Note DATEADD returns a column of dates.

userActive = 
var datamaxx = TODAY()
RETURN DATE(YEAR(datamaxx), MONTH(datamaxx), DAY(datamaxx) + 1)

You said your event_date column is a date. Not sure why you are trying to CONVERT it to DATETIME again! This is going to just add 00:00:00 to the time part in the column.

Second, why your are dividing the DateTime value into YEAR, MONTH & DATE to create a DATE value where as the variable already holding value of DATETIME type?

Now, if your only intension is to add 1 day with the current date value and wants to store the value in a new Measure, you can create this below measure simply-

date+1 = max (table1[event_date]) + 1

This +1 will increase your date value by 1 day. This will work as you said your source column's data type is date.

Related