Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
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
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 5 | |
| 5 | |
| 4 |