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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
moon_walker
Helper I
Helper I

Populating days of the week in a table

Hello

I have a table that shows the operating hours of systems by the days of the week. But not all the days of the week are listed, only a range. There are about 1000 distinct systems, with varying schedules.

 

System IDFromStart TimeToEnd Time
abcdMon7:30amFri11:59pm
abcdTue12:00amSat4:30am
abcdSat8:30amN/A11:59pm
abcdSun12:00amN/A3:00am
abcdSun8:00amN/A11:59pm
efghSun12:00amSat11:59pm
ijklMon8:00amFri8:00pm
ijklSat8:00amSun5:00am

 

And I would like to turn it into this. 7 days of the week for each system. If there are multiple time spans for a given day, then they will be in multiple columns, on the same row.

System IDDayStart Time 1End Time 1Start Time 2End Time 2Start Time 3End Time 3Duration Minutes
abcdMon7:30am11:59pmN/AN/AN/AN/A990
abcdTue12:00am4:30am7:30am11:59pmN/AN/A1260
abcdWed12:00am4:30am7:30am11:59pmN/AN/A1260
abcdThu12:00am4:30am7:30am11:59pmN/AN/A1260
abcdFri12:00am4:30am7:30am11:59pmN/AN/A1260
abcdSat8:30am11:59pmN/AN/AN/AN/A930
abcdSun12:00am3:00am8:00am11:59pmN/AN/A960
efghMon12:00am11:59pmN/AN/AN/AN/A1440
efghTue12:00am11:59pmN/AN/AN/AN/A1440
efghWed12:00am11:59pmN/AN/AN/AN/A1440
efghThu12:00am11:59pmN/AN/AN/AN/A1440
efghFri12:00am11:59pmN/AN/AN/AN/A1440
efghSat12:00am11:59pmN/AN/AN/AN/A1440
efghSun12:00am11:59pmN/AN/AN/AN/A1440
etc.etc.etc.etc.etc.etc.etc.etc.etc.

 

Any help is much appreciated.

Thank you

 

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi, @moon_walker ;

You could create a new table by dax ,then create a column.

Table 2 = GENERATE(VALUES('Table'[System ID]),{"Mon","Tue","Wed","Thu","Fri","Sat","Sun"})

create columns:

rank = SWITCH([From],"Mon",1,"Tue",2,"Wed",3,"Thu",4,"Fri",5,"Sat",6,"Sun",0)
start time = 
CALCULATE(MIN('Table'[Start Time]),FILTER('Table',[System ID]=EARLIER('Table 2'[System ID])&&[From]=EARLIER('Table 2'[From])))
sarttime2 = 
var _max=CALCULATE(MAX('Table 2'[rank]),FILTER(ALL('Table 2'),[rank]<=EARLIER('Table 2'[rank])&& [System ID]=EARLIER('Table 2'[System ID])&&[start time]<>BLANK()))
return CALCULATE(MAX('Table 2'[start time]),FILTER(ALL('Table 2'),[rank]=_max&&[System ID]=EARLIER('Table 2'[System ID])))
End time = CALCULATE(MAX('Table'[End Time]),FILTER('Table',[System ID]=EARLIER('Table 2'[System ID])))
end time2 = 
var _max=CALCULATE(MAX('Table 2'[rank]),FILTER(ALL('Table 2'),[rank]<=EARLIER('Table 2'[rank])&& [System ID]=EARLIER('Table 2'[System ID])&&[start time]<>BLANK()))
return CALCULATE(MAX('Table 2'[End time]),FILTER(ALL('Table 2'),[rank]=_max&&[System ID]=EARLIER('Table 2'[System ID])))

The final show:

vyalanwumsft_0-1659407871077.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello @v-yalanwu-msft , thank you for this attempt.

In your solution, it gives system 'abcd' a start and end time as 12:00am-4:30am. But if we see my example, system 'abcd' is online from 12:00-4:30am as well as 7:30am-11:59pm. This is for Tuesday, Wednesday, Thursday, and Friday.

 

That's why the desired solution, the ranges are split up into multiple start and end columns.

Is there a way where both these time ranges can be shown in the final table?

From my example, see Tue-Fri

System IDDayStart Time 1End Time 1Start Time 2End Time 2Start Time 3End Time 3Duration Minutes
abcdMon7:30am11:59pmN/AN/AN/AN/A990
abcdTue12:00am4:30am7:30am11:59pmN/AN/A1260
abcdWed12:00am4:30am7:30am11:59pmN/AN/A1260
abcdThu12:00am4:30am7:30am11:59pmN/AN/A1260
abcdFri12:00am4:30am7:30am11:59pmN/AN/A1260
abcdSat8:30am11:59pmN/AN/AN/AN/A930
abcdSun12:00am3:00am8:00am11:59pmN/AN/A960

 

Thank you

Much appreciated

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.