Forum Discussion
Power Query Multiple conditions - SLAs
Hi,
I am faced with a Power Query problem, and I hope someone can support me, here is a link to a sample file of orders and Public Holiday tables from our database connected to a Power Bi Report Power Query- SLA Calculation- Sal
I am trying to determine the number of orders (Order Ref) that were processed within our Service Level Agreement (SLA), here are the rules:
- Business Hours
- 7:00-19:00
- Monday to Friday
- No work on Public Holiday (Bank Holiday)
- If an order is created (Order Created Date) within business hours, then it needs to be packed on the same day. (SLA-Pass)
- If an order is created (Order Created Date) outside of business hours, then it needs to be packed (Order Packed Date) on the next available business hours. (SLA-Pass).
- If an order fails to be packed within the above conditions (2 and 3), then SLA has not been achieved (SLA-Fail).
Please reach out if you need any clarification.
Looking forward to seeing your suggestions.
Sal
7 Replies
- rubayatyasminCommunity Champion
HI, Sal29
File is not accessable. Can you see to that?
First try this solution. Create a function that determines Next business day. Example code.
let
NextBusinessDay = (inputDate as date) as date =>
let
nextDay = Date.AddDays(inputDate, 1),
nextWeekday = if Date.DayOfWeek(nextDay, Day.Monday) > 4 then Date.AddDays(nextDay, 7 - Date.DayOfWeek(nextDay, Day.Monday)) else nextDay,
Holidays = Table.Column(#"Public Holidays", "Date"), //replace with your table of public holidays
result = if List.Contains(Holidays, nextWeekday) then @NextBusinessDay(nextWeekday) else nextWeekday
in
result
in
NextBusinessDaythen in your order table calculate whether each order was processed within the SLA.
example code:
let
Source = #"Orders", //replace with your table of orders
AddedCustom = Table.AddColumn(Source, "SLA Status", each let
orderCreatedDate = [Order Created Date], //replace with your column names
orderPackedDate = [Order Packed Date],
orderCreatedTime = Time.Hour(orderCreatedDate),
orderCreatedIsBusinessHours = orderCreatedTime >= 7 and orderCreatedTime < 19 and not Date.IsInCurrentWeekend(orderCreatedDate),
deadline = if orderCreatedIsBusinessHours then orderCreatedDate else @NextBusinessDay(orderCreatedDate)
in
if orderPackedDate <= deadline then "SLA-Pass" else "SLA-Fail")
in
AddedCustomHere is the documentation on how to create function. https://learn.microsoft.com/en-us/power-query/custom-function
if my assistance helped you in any way, hit 👍.
- Sal29Frequent Visitor
Hi, apologies, I just realised that. The file should now be accessible.
I will read through your response in the meantime. Thanks
- rubayatyasminCommunity Champion
try the solutions first. then let me know if it doesn't work. I will try to look into it