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
Here is an example query with your data that shows how to get your Duration Column
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dY9LCsAgDESvUrIWP0mj9Szi/a/R1PoJ0i4EHZ6PmVKAHWaHHj0YiC6M6yGHLEI1RWLUsVB+vC+bOhJ4WdBrngexW+YPstQYVhnvll5G9309U3t2jZqhuz50/psUlyTthEjCt4R+JG1QvQE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Ticket Opened Date" = _t, #" Restored Date" = _t, #"Ticket Closed Date" = _t, #" Duration" = _t]),
#"Renamed Columns" = Table.RenameColumns(Source,{{" Restored Date", "Restored Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Ticket Opened Date", type date}, {"Restored Date", type date}, {"Ticket Closed Date", type date}, {" Duration", type number}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "DurationNew", each if [Ticket Closed Date] = null then Duration.TotalHours([Restored Date]-[Ticket Opened Date])/24 else Duration.TotalHours([Ticket Closed Date]-[Ticket Opened Date])/24),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"DurationNew", type number}})
in
#"Changed Type1".
You can then use SWITCH(TRUE() ... in a Calculated Column to get your Range using this pattern
Range =
SWITCH (
TRUE (),
Tickets[ Duration] <= 2, "0-2 Days",
Tickets[ Duration] <= 5, "3-5 Days",
Tickets[ Duration] <= 10, "6-10 Days"
)
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
mahoneypat Kindly elaborate please( I mean step by step). I am unable to distinguish between these measures.
Kindly help.
- mahoneypat6 years agoMicrosoft Employee
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
- ghouse_peer6 years agoPost Patron
mahoneypat Thanks for the solution. I got the required result. But i have one Problem the order is not the same.
when i took tht column in table it is showing this way. I need this in orderwise. ex: 0-2 Days next 3-5 Days next 6-10 Days. As discussed earlier. Kindly help.
- v-alq-msft6 years agoCommunity Support
Hi, ghouse_peer
There is no direct way to solve the problem. As a workaround, you may create a new table with range and index columns. The pbix file is attached in the end.
Test:
Then you may create a measure as below.
Rank = LOOKUPVALUE(Test[Index],Test[Range],[Date Range])Finally you can click the measure column header to sort the table visual.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.