How to calculate average working days of closed tickets? - powerbi

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]))

Related

How i can compare last week average to todays data in Power BI visual?

I want to show an hourly score for today that refreshes every hour. I built it and it works, but now I want it to compare the hourly average for the last week and if it was higher it shows a red arrow up if lower it shows a green arrow down. I don't have a problem adding the arrows as it's very easy, but I've previously added a column to the query that shows if day = today and then used it as a filter inside the visual to show today's data, so when I try to compare the results the filter also affects the calculation I created:
Measure = calculate(average(rawdata[contacts]),rawdata[Week to Average = 1)
week to average is the column that tells if the week was the previous week is simply if(weekcolumn=weeknum(today())-1,1,0)
Do you know any way i can compare last week average to todays data?
Also visual that i used is a matrix
This is just an idea. So if it is enough to solve the case then ok. If it's not it, then, please, add more info about your data table - a screenshot or sample data. how you calculate your average and what do you mean by average? At least what kind of data you are dealing with is it a sum of some values per day, do you have a different number of values for each day? etc.
measure 1:
averContacts = AVERAGE(rawdata[contacts]) -- no CALCULATE()
measure 2:
avrToday =
CALCULATE(
[averContacts]
,TreatAS({TODAY()}, yourTable[DatesColumn])
)
measure 3:
aveLastWeek =
VAR prevWeekEnd = TODAY() - WEEKDAY(Today(),2) -- 2 -> Mon-Sun week format
VAR prevWeekStart = prevWeekEnd - 7
VAR DatesLastWeek = CALENDAR(prevWeekStart ,prevWeekEnd)
RETURN
CALCULATE(
[averContacts]
,TreatAS(DatesLastWeek, yourTable[DatesColumn])
)
measure for your visual
lastWeek_vs_Today = DIVIDE(avrToday ,aveLastWeek)

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 ))

Power BI Question - Creating Week Over Week % change based on ISOWeek index in a table

I have a dataset that contains multiple dimensions with metrics and trying to create Week over week change based on "ISOweek" indicator created as a separate column.
So the original dataset looks like,
dimensions [Date, product, location] and metrics [budget allocated]
The challenge I cannot figure out is that
I created a table in the dashboard that is supposed to have,
dimensions [ISOindice] and Metrics [Spend, Spend Week over week change %]
To do this, I created ISO week indicator, starting Monday using the below formula.
ISOindice = dataset[ISO Year] & "-" & FORMAT(dataset[Week Number], "00")
Where, Week Number = WEEKNUM(dataset[date], 21)
And, ISO Year = YEAR(dataset[date] + 26 - dataset[Week Number])
and put this dimension into the table I created above with spend and WoW spend % metrics
However it`s not picking up the number correctly.
I tried using things like Earlier or MAX(ISOindice) etc..
but it looks like because there are multiple rows existing for a single ISOindice element in the original dataset (due to product and location columns..), it`s not working.

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]))

PowerBI / DAX calculation between two dates for last 5 days

I am trying to show a bar graph that shows the total waiting for review for each day of the last 5 days. something like this, day is 4th, 5th, 6th jan.
The data i have is a start date and end date, if the day is between those two days the status is waiting for review. What i would like is on bar graph with days on x axis and total waiting for review on y axis. So we can look at the graph and say there was 10 on this day etc.
The graph above is just the end date using this formula:
OutputCerts = CALCULATE(COUNT(JobID[HSNo]),USERELATIONSHIP(JobID[WLPDispatchDate],Calender[Date]))
but i am unsre of how to get to what i want. I think im going in the wrong direction with the above.
Solved it with this formula:
_openRecords =
VAR date_to_examine =
MAX(Calender[Date])
VAR number_orders =
CALCULATE(
DISTINCTCOUNT(JobID[HSNo]),
KEEPFILTERS(date_to_examine > JobID[StartDate] && JobID[StartDate]<>BLANK()),
KEEPFILTERS(date_to_examine < WorkCardReview[ApproveDate] || WorkCardReview[ApproveDate]=BLANK())
)
RETURN
IF (ISBLANK(number_orders), 0, number_orders)
works nicely with slice filter for date