Forum Discussion
Switch function
- 4 years ago
Hi ksmith0411 ,
Whether you need to save the first row as variable which named 'Hour_Part' and create the calculated column like this:
Column 2 = VAR Hour_Part = TIME ( HOUR ( Actual[Start Time] ), MINUTE ( Actual[Start Time] ), SECOND ( Actual[Start Time] ) ) RETURN SWITCH ( TRUE (), Hour_Part > TIME ( 8, 0, 0 ) && Hour_Part < TIME ( 9, 0, 0 ), TIME ( 9, 0, 0 ) )Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you so much that worked.
I have another query you might be able to help with, I also need to create a table that looks like the below, however Im not sure where to start with a formula
Hi ksmith0411 ,
Noticed that there are duplicated rows in the table so that the table visual and matirx visual would just show the aggreated value.
Basically you can create the below query in Power Query editor:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrC0MjBQcPRV0lEyNLAyNAUxY3WiQRxjmLgRiBkAFYeydZSMQRqhosYgnWBRUyS1pBgdCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start Time" = _t, #"End Time" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Time", type time}, {"End Time", type time}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Time", each List.Times(#time(8,0,0),13,#duration(0,1,0,0))),
#"Expanded Time" = Table.ExpandListColumn(#"Added Custom", "Time"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Time",{{"Time", type time}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type1", "Diff", each if [Time] >= #time(Time.Hour([Start Time]),0,0) and [Time] < [End Time] then if [Time] > [Start Time] and [Time] = #time(Time.Hour([End Time]),0,0) then Duration.Minutes([End Time]- [Time]) else if [Time] < [Start Time] and [Time] = #time(Time.Hour([Start Time]),0,0) then Duration.Minutes(#time(Time.Hour([Start Time])+1,0,0) - [Start Time]) else 60 else 0),
#"Changed Type2" = Table.TransformColumnTypes(#"Added Custom1",{{"Diff", Int64.Type}})
in
#"Changed Type2"
Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.