Forum Discussion
Anonymous
5 years agoNot applicable
Wrong outcome using DATEDIFF
In the screenshot below you can see my Power BI page. I want to calculate the days between two dates. I want to have the number of days from VALIDFROM to Tot Datum. But when the Tot Datum is not with...
Anonymous
5 years agoNot applicable
Thanks for you reply. VALIDFROM is a column from the contracts table while Tijd in Leegstand is a measure. I modified your column somewhat by:
Tijd in Leegstand =
VAR maxdate =
MAX ( 'Dim_Datum Periode'[Datum] )
VAR totdatumdate =
PMCCONTRACT[Tot Datum]
VAR comparedate =
IF (
maxdate < totdatumdate, maxdate, totdatumdate)
RETURN
DATEDIFF (
PMCCONTRACT[VALIDFROM],
comparedate,
DAY) + 1
According to my logic this should give the right result but it still only gives the correct values when maxdate > totdatumdate but not when maxdate < totdatumdate. This is because I want maxdate to depend on the slicer Periode you see in my first post. Maxdate should now be 31-10-2020 but when I change the slicer to, for example 12-11-2020, maxdate should change too. I understood that this cannot be done using a column as they are not dynamic so is there a way to create what I want using a measure?