DAX - How to use DATESBETWEEN in SWITCH function - powerbi

I am having a bit of tough time wrapping my head around this. I have a column based on response time in hours and our company's SLA (service level agreement) is that all incoming inquires should be answered within 2 days (the response time in hours is total hours spent on responding to inquiry).
The problem is that our company operates with winter time (7 h 45 min) and summer time (7 h). My dataset consist both and I want Power BI to differietiate winter and summer time when I try to compute SLA. In winter time 1 working day = 7 h 45 min and in summer time = 7 h. I have just used the average of summer/winter time = 7 h 30 min. The SLA column consist 3 data types, "Innen en arbeidsdag", "Innen to arbeidsdager" and "over 2 arbeidsdager".
I have used the following syntax:
SLA = SWITCH(TRUE(),Response time in hours>15, "Over to arbeidsdager", esponse time in hours>7.5, "Innen to arbeidsdager", Response time in hours<=7.5, "Innen en arbeidsdag")
How can I use DATESBETWEEN in this syntax to tell Power BI that Response Time YTD column from 15th May to 15th September is summer time, Working day = 7 h?

Just as an idea, I wouldn't use DATESBETWEEN. If you want to input dates directly to logically categorize your work seasons, try this:
SWITCH(TRUE()
,'Date'[Date] >= DATE(2022,5,15)
&& 'Date'[Date] <= DATE(2022,9,15)
,7
,BLANK()--You can carry on with logic for other seasons
)
I am using this syntax on a date table, but you can do this with any table that has a date column.

My dataset is called 'Masterdata' and my columns looks like this:
Svartid i t SLA
6,12 Innen en arbeidsdag
11,73 Innen to arbeidsdager
20,42 Over to arbeidsdager
1,07 Innen en arbeidsdag
etc etc
My syntax so far:
SLA = SWITCH(TRUE(),Masterdata[Svartid i t]>15, "Over to arbeidsdager", Masterdata[Svartid i t]>7.5, "Innen to arbeidsdager", Masterdata[Svartid i t]<=7.5, "Innen en arbeidsdag")
So how can implement
SWITCH(TRUE(),'Date'[Date] >= DATE(2022,5,15) && 'Date'[Date] <= DATE(2022,9,15),7,BLANK()
In my syntax?

Related

How do I sum the available hours in a given period in PowerBI based on the following?

I have some data I am working with that has the number of minutes someone works in a given day
I would like to sum this amount based on the filter context being daily weekly monthly etc
`
Utilization_Rate =
Var Actual_Job_Length =
SUMX(
FILTER(
MATCHED_JOBID,
MATCHED_JOBID[ACTUAL_END]>MATCHED_JOBID[ACTUAL_START]),
DATEDIFF(
MATCHED_JOBID[ACTUAL_START],
MATCHED_JOBID[ACTUAL_END],
MINUTE))
VAR UTILIZATION =
DIVIDE( Actual_Job_Length, TIME AVAILABLE)
RETURN UTILIZATION
`
My issue is with this time available function. I want to be able to utilization based on the day, week start date, month, quarter, and year
I need to sum the available hours based on a 5 day work week. If a employee works more than 30 they must have 8 hour days (fulltime) if an employee works 30 or less then 6 hour days.
I do not know how to do the above and have function for different period lengths. If I need multiple measures that is fine too. Just don't know how to approach it
I have not figured out anything to do
I got further
PT-FT =
CALCULATE(IF( [Total_Job_Duration]>= VALUES('Calendar Lookup'[PT_hours]), VALUES('Calendar Lookup'[FT_Hours]), VALUES('Calendar Lookup'[PT_hours])), FILTER(Matched_JobID, Matched_JobID[Actual_Start].[Date]))
This works to some extent but I still have a problem with it not summing for the number of work days in a period
Result of the above code
I want it for example in this case to sum for the week as the other values have so I would see 40 instead of 8 and 30 instead of 6
Please use the below measure. Its working fine at my end:
Quantity_based_OnSlicer =
var Daily = SELECTEDVALUE('Product'[Date])
var Monthly = year(selectedvalue('Product'[Date])) & MONTH(SELECTEDVALUE('Product'[Date]))
var weekly = WEEKNUM(SELECTEDVALUE('Product'[Date]))
Return
SWITCH(SELECTEDVALUE('Ex5-Slicer'[Value]),
"Daily",CALCULATE(SUM('Product'[Quantity]),'Product'[Date] = Daily,ALLEXCEPT('Product','Product'[Date])),
"Monthly",CALCULATE(SUM('Product'[Quantity]),year('Product'[Date])&month('Product'[Date]) = Monthly,ALLEXCEPT('Product','Product'[Date])),
"Weekly",CALCULATE(SUM('Product'[Quantity]),WEEKNUM('Product'[Date]) = weekly,ALLEXCEPT('Product','Product'[Date])),
0
)

Prior year returning blanks power bi

Today I come to you with a question regarding a report I am working on finishing up, So I have a lot of Year over year measures in this project, and they all run okay except for 2 of them, its one called "First time complete % 2020" and "Days to first visit 2020", So what is the issue?
When I have a table with claim numbers / customer numbers etc it looks good, I then add the 2021 measures for Current year, this looks good too, when adding the 2020 or prior year measure it is all blank though, and if i do just claim number and remove the Current year measure so i have a table with just prior year and claim number it makes the entire table blank, even the claim number column.
I have attached photos of what I am explaining, the relationship is a 1 to many with 1 being on my calendar side, many on the fact table side.
here is the code for the prior year measure I am using First time complete % 2020 = CALCULATE([Percentage of First Time Complete], 'Calendar(Based on PaidDT Adjusted)'[Year] = 2020)
I have also tried the date add method with CALCULATE([First time complete % 2020], DATEADD('Calendar(Based on PaidDT Adjusted)'[Date], -1, YEAR))
Hope this helps. Thanks
Think about your filter context (filters/slicers/ row level), is there any of them?
If soo, then you need to break this filter by using this kind of calculation:
SomeMeasure = CALCULATE( [YourBaseMeasure], FILTER( ALL('DateTable'[YEAR]), 'DateTable'[YEAR] = 2020))
or something more dynamic:
SomeMeasure = CALCULATE( [YourBaseMeasure], FILTER( ALL('DateTable'[YEAR]), 'DateTable'[YEAR] = SELECTEDVALUE('DateTable'[YEAR])-1 ))

Seperating sickness between months in PowerBI

I have set up a table showing number of sick days based on absence start and finish date in Power BI. The date tables have been set up.
I am having an issue with sick days that continue in the following month, for e.g .
Absence Start Date
5 May 21
Absence End Date
5 June 21
My table sums all the absence days in May.
How do I allocate the 25 days in May and then the remaining go to June even though it is one occurrence?
How Data is being summarised
Unfortunately you don't provide enough information about your model/ data. Consider this example. Here is my dummy table:
Table 3 =
var __baseTable =
DATATABLE("StartD",DATETIME, "EndD", DATETIME,
{
{"2020-01-28","2020-02-24"},
{"2019-12-23","2020-01-31"},
{"2020-01-20","2020-02-17"}
}
)
return
ADDCOLUMNS(GENERATE(__baseTable, CALENDAR([StartD],[EndD])),"Month", FORMAT([Date],"yyyy-mm"), "WorkDay", IF(NOt(WEEKDAY([Date]) in {1,7}) ,1,0))
And here are measures (calculating days without a weekend, because I don't have Calendar with businessHoliday):
SumOfSickDays = CALCULATE(SUM('Table 3'[WorkDay]))

Power BI measurement between fixed Date and calculated Date

I'm interested in creating a report comparing a before and after of two equivalent time periods.
The after period is looking at the days from a fixed date (1/10/20) to the most recent case in the tbl_Data table (in this case it is 92 days).
The before period would subtract the calculated 92 days from the fixed date (1/10/20).
I was able to get the days between part fairly easily using the following:
Days_Between =
calculate(
countrows(date_table),
DATESBETWEEN(
date_table[Date_field].[Date],
date(2020,10,01),
MAX(tbl_Data[Date Received])
)
)
However I'm at odds on how to subtract this from the fixed date to get a date range I can filter on easily. Any pointers/ideas would be greatly appreciated.
Cheers
First, I would simplify your days calculation: Days_Between = DATEDIFF(date(2020,10,01), MAX(tbl_Data[Date Received]), DAY ). Then, I would simply subtract the result from the given date. Start date = Date(2020, 10, 1) - [Days_Between]

How to calculate average working days of closed tickets?

So, I am new to Power BI and my database is a bit weird. it looks like this:
Ticket Open Date Close Date
BR001 02/01/2020 02/01/2020
BR001 02/01/2020 10/01/2020
BR001 12/02/2020 14/02/2020
BR002 02/02/2020 04/02/2020
BR002 05/02/2020
The reason it looks like this is that because some tickets are reopened up to 5-6 times. If the last row of the ticket does not contain a closing date, it means the ticket is still open for the time being. The result that would be ideal to me (I don't know if it's even possible) is to have 8 working average days for the first ticket in a matrix or table (excluding weekends) and not taking into account the second ticket since it's still open.
The desired output should look something like:
Ticket Average working days
BR001 8 Days
BR002 null
Is it possible to have a result like that? Or what would be the closest thing to it? I am also open to transform the data with M-Query.
Thanks a lot in advance!
First we add a column to the table:
DaysOpen = DATEDIFF(Tickets[Open Date], Tickets[Close Date], DAY)
This is simply doing a countdiff in days between open & close. Next we calculate the dayx of the weekends in a new column:
WeekendDays =
var overRun = WEEKDAY(Tickets[Close Date], 2) - MOD(Tickets[DaysOpen], 7)
var lastWeekend = if (overRun < 0, -overrun, 0)
return lastWeekend + ROUNDDOWN(Tickets[DaysOpen]/ 7, 0) * 2
There are 2 aspect: Calculate how many weekend we have for sure by dividing by 7 and multiply this by 2.
Check if there are days left which fall in weekend. I called it overrun.
Then we calculate the workdays:
WorkingDays = Tickets[DaysOpen] - Tickets[WeekendDays]
to summarize it all we create a new table:
TicketAveOpen = SUMMARIZE(FILTER(Tickets, not ISBLANK(Tickets[DaysOpen])),Tickets[Ticket],"TotalDaysOpen", SUM(Tickets[WorkingDays]))