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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
pattarom
New Member

Filling a column following specific rules

Hi

I have a table containing data in this form (simplified):

 

DateTimeTimeSlotmeasure1measure 2
2022-01-10 00:00:00 310
2022-01-10 01:00:00 23211
2022-01-10 02:00:00 34
2022-01-10 03:00:00 45

 

I have many tables of this type (one table for each monitored element), where the DateTime column is starting at the beginning of the year with hourly intervals. Collected data are queued weekly by my colleagues.

Every element has its time slot definition consisting of three levels (high, mid, low) changing by time and day of the week.

 

An example of a rule is (times are in 24h format): From Monday to Friday, from 00:00 to 07:00 level is low, from 07:00 to 08:00 level is mid, from 08:00 to 17:00 level is high, from 17:00 to 19:00 level is mid and from 19:00 to 00:00 level il low. Saturday, Sunday, and holidays levels are always low.

 

I need to fill the TimeSlot column with a level, following the rule I wrote in the example.

TimeSlot column will be used later to filter data in reports.

 

I'm figuring out how to approach this problem.

Thank you in advance.

 

Michele

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@pattarom , You can create a new column like


Switch(True() ,

Weekday([datetime],2) >=6 || Timevalue([DateTime]) <= time(7,0,0) || (Timevalue([DateTime]) > time(19,0,0) ) , "Low"
(Timevalue([DateTime]) > time(7,0,0) && Timevalue([DateTime]) <= time(8,0,0) ) || (Timevalue([DateTime]) > time(17,0,0) && Timevalue([DateTime]) <= time(19,0,0) ) , "Mid" ,
"High")

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@pattarom , You can create a new column like


Switch(True() ,

Weekday([datetime],2) >=6 || Timevalue([DateTime]) <= time(7,0,0) || (Timevalue([DateTime]) > time(19,0,0) ) , "Low"
(Timevalue([DateTime]) > time(7,0,0) && Timevalue([DateTime]) <= time(8,0,0) ) || (Timevalue([DateTime]) > time(17,0,0) && Timevalue([DateTime]) <= time(19,0,0) ) , "Mid" ,
"High")

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.