Forum Discussion
Calculation with date/hours?
- 9 years ago
Please check a formula as below.
Hours Between = VAR elapsedHours = DATEDIFF ( YourTable[Open Date], YourTable[Closed Date], HOUR ) RETURN IF ( ISBLANK ( YourTable[Closed Date] ), BLANK (), SWITCH ( TRUE (), elapsedHours <= 12, "12", elapsedHours <= 24, "24", elapsedHours <= 36, "36", elapsedHours <= 48, "48", elapsedHours <= 72, "72", elapsedHours <= 240, "240", "Over 240" ) )If it answers your question, please accept it as solution to close this thread. For any question, feel free to post.
For difference in dates in hours, try playing with the below logic:
Var = FORMAT( [Closed Date] - Table1[Open Date], "DD" ) * 24 + FORMAT( [Closed Date] - Table1[Open Date], "hh" )
As for Banding, try playing with the below approach:
=
SWITCH (
TRUE (),
[Time between] < 12, "<12",
[Time between] >= 12 && [Time between] <= 24, "12-> 24",
"24+"
)
The switch statement can go on forever so put in as many bands as you'd like!
There is a better approach than this by levaerging a banding table by the way. It is quite an advanced technique and can cause some issues with relationships unless you're comfortable with data modelling. If you're interested I can post details.