Jamini Rath
Jamini Rath

Reputation: 31

How to calculate fraction in datediff function in Tableau

I am not really an expert in Tableau. I have a need to calculate a timedifference in hours, but also want to see fraction of an hour. I am using Tableau 9.

I used the function IF DATEDIFF("hour", [CL2_Start_Time_ST], [CL2_End_Time_ST]) > 8 then NULL ELSE DATEDIFF("hour", [CL2_Start_Time_ST], [CL2_End_Time_ST]) END

If the time difference between CL2_Start_Time_ST and CL2_End_Time_ST is less than 1 hour (for example 30 minutes) the result is 0, but I want to see 0.5 in result.

I dont want to calculate in time difference in minutes since all my other calculations are in hours and hence it is easier to create a relative plot with other calculations.

Please help.

Upvotes: 1

Views: 462

Answers (1)

Jamini Rath
Jamini Rath

Reputation: 31

I found the answer to the above question. The simple formula below worked. I was using DIV function and that caused the issue.

IF DATEDIFF("hour", [CL2_Start_Time_ST], [CL2_End_Time_ST]) > 8 then NULL
ELSE (DATEDIFF("minute", [CL2_Start_Time_ST], [CL2_End_Time_ST])) / 60
END

Upvotes: 1

Related Questions