The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event! Join us in Stockholm, Sweden from September 24-27, 2024.
2-for-1 sale on June 20 only!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi,
Im trying to do a swicth query between two times ie if Start time >=08:00:00 & End time <=09:00:00 then return 09:00:00 but im not having any joy
If anyone can help that woul dbe great.
Thanks
K
Solved! Go to Solution.
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.
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.
I agree that I would probably do this in the query editor, but here is a DAX column expression that should work.
NewColumn =
IF (
AND (
Actual[Start Time] >= TIME ( 8, 0, 0 ),
Actual[Start Time] <= TIME ( 9, 0, 0 )
),
TIME ( 9, 0, 0 ),
BLANK ()
)
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Try it this way--assume your prior step is named PriorStep:
= Table.AddColumn(PriorStep, "Next Hour", each Time.StartOfHour(Time.From([End Time] + #duration(0,1,0,0))))
--Nate
HI Nate,
Thanks for coming back to me, Im afraid Im a complete novice on power BI ive tried this but think I'm entering it in wrong.
Thanks
K
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the June 2024 Power BI update to learn about new features.
User | Count |
---|---|
34 | |
19 | |
18 | |
16 | |
13 |