cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PH573
Regular Visitor

Expanding day of week and time data

Hello,

 

I am trying to format availability data for apps in a way that would give each day of the week its own row, as opposed to having availability that starts on one day and end in another be in the same column.

 

In its current form, the data looks like this:

ApplicationStart dayStart timeEnd dayEnd time
Generic

Sun

00:00:00Sun

19:00:00

GenericMon00:00:00Fri23:59:59
GenericSat00:00:00Sat19:00:00
Generic2Sun00:00:00Sat23:59:59

 

I would like for it to look like this:

 

ApplicationDayStart timeEnd time
Generic
Sun00:00:0019:00:00
GenericMon00:00:0023:59:59
GenericTue00:00:0023:59:59
GenericWed00:00:0023:59:59
GenericThu00:00:0023:59:59
GenericFri00:00:0023:59:59
GenericSat00:00:0019:00:00
Generic2Sun00:00:0023:59:59
Generic2Mon00:00:0023:59:59
Generic2Tue00:00:0023:59:59
Generic2Wed00:00:0023:59:59
Generic2Thu00:00:0023:59:59
Generic2Fri00:00:0023:59:59
Generic2Sat00:00:0023:59:59

How could I achieve this in Power BI? Thank you in advance for any assistance.

 

EDIT: updated sample data for better clarity on what I am trying to do

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @PH573 ;

You could try to create a new table.

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

Then create columns:

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

The final show:

vyalanwumsft_0-1659429706411.png

vyalanwumsft_1-1659429724587.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.

View solution in original post

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @PH573 ;

You could try to create a new table.

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

Then create columns:

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

The final show:

vyalanwumsft_0-1659429706411.png

vyalanwumsft_1-1659429724587.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 Yalan,

 

Thank you very much for this! It has helped immensely.

 

After some new data was added, I ran into an edge case where an app has three availability ranges, shown below. How can I apply this logic for this particular app?

 

ApplicationStart dayStart timeEnd dayEnd time
Generic3Mon12:00:00AMFri6:30:00AM
Generic3Mon8:30:00AMFri6:00:00PM
Generic3Sun10:00:00PMThu

11:59:59PM

The end result should look like this:

ApplicationDayStart TimeEnd TimeStart Time2End Time2Start Time3End Time3
Generic3Sun10:00:00PM11:59:59PM    
Generic3Mon12:00:00AM6:30:00AM8:30:00AM6:00:00PM10:00:00PM11:59:59PM
Generic3Tue12:00:00AM6:30:00AM8:30:00AM6:00:00PM10:00:00PM11:59:59PM
Generic3Wed12:00:00AM6:30:00AM8:30:00AM6:00:00PM10:00:00PM11:59:59PM
Generic3Thu12:00:00AM6:30:00AM8:30:00AM6:00:00PM10:00:00PM11:59:59PM
Generic3Fri12:00:00AM6:30:00AM8:30:00AM6:00:00PM  
Generic3Sat      
vanessafvg
Super User
Super User

do you have the actual date time or is it provided to you in a day / time of day format?

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




As helpful as datetime would be, it is provided to me as just day of the week + time.

Helpful resources

Announcements
Vote for T-Shirt Design

Power BI T-Shirt Design Challenge 2023

Vote for your favorite t-shirt design now through March 28.

March 2023 Update3

Power BI March 2023 Update

Find out more about the March 2023 update.

March Events 2023A

March 2023 Events

Find out more about the online and in person events happening in March!

Top Solution Authors