Forum Discussion
subtracting days from Date variable
I am trying to subtract days from date varible that I have calculated in formula but I am getting the error.
An argument of function 'DATE' has the wrong data type or the result is too large or too small.
Code:
Zero has the same problem as negative numbers in that there is no zeroth day of the month.
Your column definition is simpler as follows:
Column 3 = VAR firstperiod = "12/28/2020 to 01/24/2021" VAR StartDate = DATEVALUE ( RIGHT ( firstperiod, 10 ) ) VAR FP_ED = StartDate VAR FP_SD = StartDate - 27 VAR SP_SD = FP_SD - 1 VAR SP_ED = SP_SD - 27 RETURN SP_ED
5 Replies
- edhansCommunity Champion
Just subtract from the date, not the day. So Date(2021,1,1) - 1 will return Dec 31, 2020.
What I suspect is happening is where you are doing -27 it is returning a negative day which messes up the DATE() function. Just calc the date, then add/subtract days. In this case DAX is just like Excel.
- siva_powerbiHelper IV
Thanks for reply..
Negative days are being handled correctly when I do -27 I am getting 0 which is being not handled in DAX.
- AlexisOlsonSuper User
Zero has the same problem as negative numbers in that there is no zeroth day of the month.
Your column definition is simpler as follows:
Column 3 = VAR firstperiod = "12/28/2020 to 01/24/2021" VAR StartDate = DATEVALUE ( RIGHT ( firstperiod, 10 ) ) VAR FP_ED = StartDate VAR FP_SD = StartDate - 27 VAR SP_SD = FP_SD - 1 VAR SP_ED = SP_SD - 27 RETURN SP_ED