Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
hllary
New Member

Create column based on Time value in another column

I am trying to create a visual that will so how many items were inspected during a certain time period.

 

hllary_0-1648841859104.png

 

I'm thinking the easiest way to do this is create another column that will have TimeName, then I can create a visual that will count the TimeName during a day.  How do I create the column based on the records time being between two other times?  Or is there a better way of doing this. A sample of the time is below.

 

hllary_1-1648841941901.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @hllary ,

Here are the steps you can follow:

1. Create calculated column.

Flag =
CALCULATE(MIN('Table'[TimeName]),filter('Table',[start]<=earlier('Table2'[date_insp_time]) &&[end]>= earlier('Table2'[date_insp_time])))

New Column =
var _count=
COUNTX(FILTER( ALL('Table2'),'Table2'[Flag]=EARLIER('Table2'[Flag])),[Flag])
return
[Flag] &" "&_count&" Project"

2. Result:

vyangliumsft_0-1649144019327.png

Please click here for the pbix file

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi  @hllary ,

Here are the steps you can follow:

1. Create calculated column.

Flag =
CALCULATE(MIN('Table'[TimeName]),filter('Table',[start]<=earlier('Table2'[date_insp_time]) &&[end]>= earlier('Table2'[date_insp_time])))

New Column =
var _count=
COUNTX(FILTER( ALL('Table2'),'Table2'[Flag]=EARLIER('Table2'[Flag])),[Flag])
return
[Flag] &" "&_count&" Project"

2. Result:

vyangliumsft_0-1649144019327.png

Please click here for the pbix file

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

@hllary 

 

 

Time Table

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjFQ0lEytjIwACIgywzKitUBShkiCegoWSBLGSEJ6CgZGiDLGSOLAJlGVsYISRNkESDTBCYZCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Time Key" = _t, Start = _t, End = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time Key", type text}, {"Start", type time}, {"End", type time}})
in
    #"Changed Type"

 

Time Data

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjSyMjKwMjBQitUBcoyROGZWhqZwCQMrY4QqEysjiEwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type time}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Add Time Key", (x) => Table.SelectRows(#"Time Table", each x[Time] >= [Start] and  x[Time] < [End] ){0}[Time Key] , type text)
in
    #"Added Custom"
 
ryan_mayu
Super User
Super User

@hllary 

you can try to create a column

maxx(filter(table1,start<=DATE_INSP_Time&&end>=DATE_INSP_Time),TimeName)





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @hllary  - I have created the following PBIX example to show how you can use Power Query syntax to find the Time Band.  Sample File   .  Please note the range removes the +1 second from the time ranges.

 

DarylLynchBzy_0-1648844590010.png

DarylLynchBzy_1-1648844664975.png

 

Thanks for you help!  This project is for work and they have an older version of power bi.  Please post the the code to the power query.  thanks

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.