Forum Discussion
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.
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.
- Anonymous4 years ago
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:
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
5 Replies
- AnonymousNot applicable
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.
- hllaryNew Member
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
- ryan_mayuSuper User
you can try to create a column
maxx(filter(table1,start<=DATE_INSP_Time&&end>=DATE_INSP_Time),TimeName)
- AnonymousNot applicable
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" - AnonymousNot 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:
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