Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for
Did you mean:
Contributor II

## DATEDIFF function in qlik sense

Hi community,

Iam new to qlik sense and starting to evaluate it as a BI Tool and trying to do a simple calculation with DATADIFF, but DATEDIFF is not a valid function in qlik ,can please help me to convert SQL code to qlik sense script ?

"Technical CO2" / 365.0 *

case when (datediff(DAY, case when DateFinExo > min(Calcul_Datedebut)  then DateFinExo else min(Calcul_Datedebut) end,  max(Calcul_DateFin) )+1 <= 0) or (datediff(DAY, min(Calcul_Datedebut),max(Calcul_DateFin)) < 30) then 0

else datediff(day, case when DateFinExo > min(Calcul_Datedebut)  then DateFinExo else min(Calcul_Datedebut) end,  max(Calcul_DateFin) )+1

end

Labels (4)

• ### Scripting

1 Solution

Accepted Solutions
MVP

Maybe something like this?

``````[Technical CO2]/365.0 *
If(Max(Calcul_DateFin)-RangeMax(DateFinExo,Min(Calcul_Datedebut))+1 <= 0 or Max(Calcul_DateFin)-Min(Calcul_Datedebut) < 30,
0,
Max(Calcul_DateFin)-RangeMax(DateFinExo,Min(Calcul_Datedebut))+1)``````

2 Replies
MVP

In Qlik, you can simply subtract or add dates. Date1 - Date2 will give you the difference in days (if they're a timestamp, it'll include the time aspect, e.g. 1.5 is a day and a half).

MVP

Maybe something like this?

``````[Technical CO2]/365.0 *
If(Max(Calcul_DateFin)-RangeMax(DateFinExo,Min(Calcul_Datedebut))+1 <= 0 or Max(Calcul_DateFin)-Min(Calcul_Datedebut) < 30,
0,
Max(Calcul_DateFin)-RangeMax(DateFinExo,Min(Calcul_Datedebut))+1)``````

Community Browser