Forum Discussion
Duration Days
- 6 years ago
The first block of M code is not a measure but an example of how to create the Duration column. Basically, in the query editor on the Add Column tab, click on Custom Column and then put an expression like this in the pop up box, substituting your actual column names in.
= if [Ticket Closed Date] = null then Duration.TotalHours([Restored Date]-[Ticket Opened Date])/24 else Duration.TotalHours([Ticket Closed Date]-[Ticket Opened Date])/24Then, hit Close & Apply to load the data with the new column, and then click on New Column in the ribbon and enter the DAX expression to get your new Days Range column (follow the pattern started to add more date ranges).
Regards,
Pat
Hi, ghouse_peer
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create two measures as below.
Duration =
var _restoredate = SELECTEDVALUE('Table'[Restored Date])
return
IF(
NOT(ISBLANK(_restoredate)),
var hours = DATEDIFF(SELECTEDVALUE('Table'[Ticket Opened Date]),_restoredate,HOUR)
var result1 = INT(hours/24)+MOD(hours,24)/24
return
result1
,
var hours = DATEDIFF(SELECTEDVALUE('Table'[Ticket Opened Date]),SELECTEDVALUE('Table'[Ticket Closed Date]),HOUR)
var result2 = INT(hours/24)+MOD(hours,24)/24
return
result2
)
Date Range =
IF(
ISFILTERED('Table'[Ticket Opened Date]),
SWITCH(
TRUE(),
[Duration]>=0&&[Duration]<=2,"0-2",
[Duration]>=3&&[Duration]<=5,"3-5",
[Duration]>=6&&[Duration]<=10,"6-10",
[Duration]>=11&&[Duration]<=30,"11-30",
[Duration]>=31&&[Duration]<=60,"31-60",
[Duration]>=61&&[Duration]<=90,"61-90",
[Duration]>=91&&[Duration]<=120,"91-120",
[Duration]>=121&&[Duration]<=150,"121-150",
[Duration]>=151&&[Duration]<=180,"151-180",
"181+"
)
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- ghouse_peer6 years agoPost Patron
v-alq-msft Thanks for the suggestions, solutions which u hv provided. It helped me a lot to learn how we can workaroud in another way. The way u showcased the solution through PBIX file. Thank you very much.