PowerBI / DAX calculation between two dates for last 5 days - powerbi

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

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)

How to Get Custom Week Desc in DAX

Basis on below data I want to add a calculated column with Week Description
I've done it in excel by typing it manually.
Also my week is starting from Thursday and ends on Wednesday hence I've Used this function to get the weekday WEEKDAY('Calendar'[date],14)
Requesting you to help me with a dax code which can be used to create a new calculated column with week information as shown below in third column.
The logic would be : If the date is current week then the value will be "This Week" else if the
date is in last week then "This Week -1" else if the date is in last to last week then "This Week - 2" and so on.
The weekday can be calculated as following:
Weekday = WEEKDAY([Date] + 3)
We do a shift of 3 days to make Thursday the start of the week
Next, we get the WeekDesc in two steps, frist we calculate the difference between now and the date in weeks and as second step we use an if statement to create the correct sting (and logic).
WeerDesc =
var weeksPast = DATEDIFF(now(), [Date] + 3,WEEK)
return if ( weeksPast = 0, "This Week", "This Week" & weeksPast)
As you can see you can use variables in your DAX, I would recommend using them to keep the overview.
Enjoy
We can do this also in this way (as a measure if you need only label to display on rows):
DayOfWeek = WEEKDAY(SELECTEDVALUE('CAL'[Date]),14)
DiffToToday = DATEDIFF(SELECTEDVALUE('CAL'[Date]),TODAY(),DAY)
Label = CONCATENATE("This Week", (DIVIDE( CAL[DiffToToday] + CAL[DayOfWeek],7) -1) *-1 )
Of course, we can do all steps in one measure.

Year over year running month total percentage change in power bi

I've been struggling with this for a while. I need to calculate running month total percentage change year over year. I got it working but its not getting the running total for the month to do the calculation. By the way this is on the graph. Here are my calculations below:
how graph looks
ImprovementIncidentPercentage = 1 - DIVIDE([CurrYearIncidents],[LastYearIncidents],0)
CurrYearIncidents = CALCULATE(count(VW_RI_INCIDENTONLY_PBI[Incident]),
Filter(VW_RI_INCIDENTONLY_PBI,VW_RI_INCIDENTONLY_PBI[EVENTDATE].[Year] =('newsecondyear'[SecondYearValue])))
LastYearIncidents = CALCULATE(count(VW_RI_INCIDENTONLY_PBI[Incident]),
Filter(VW_RI_INCIDENTONLY_PBI,VW_RI_INCIDENTONLY_PBI[EVENTDATE].[Year] = 'newfirstyear'[FirstYearValue]))
The second and first year value is used as slicers for them to be able to pick two years they want to see the percentage improvement on:
slicers to pick what two years to do percent improvement on
I know something has to change CurrYearIncidents and LastYearIncidents so it does the calculation for running total for the month not the monthly total. I am just not sure how to make it work. Here is the close look at the issue.
show as table graph of error
For January the calculation is correct 1-(10/14) = 28.6%
For February it should be 1-(30/29) but instead it does monthly total for february and doesn't add up january so it does 1-(20/15)
To get accumulation values month over month I use this measure:
Cumulative events = TOTALYTD ( count (VW_RI_INCIDENTONLY_PBI[INCIDENT]), VW_RI_INCIDENTONLY_PBI[EVENTDATE].[Date])
Please help!

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

Retrieving parameter from relative date Slicer Power BI

I have a calculation that is being done on a weekly basis (x+y/x*40) . 40 is the number of hrs worked per week and x is the num of weeks selected.
I have a relative date slicer using which the user will select the number of weeks. The catch is that there are two kinds of relative weeks - one from the present day and one is the entire week.
If the user selects 2 weeks it will be (x+y/2*40).
I have a calculation called
Tot Weeks = DATEDIFF(MIN( DimDate[Calendar Date] ), MAX( DimDate[Calendar Date]), week )
However, this doesn't work well if I select 'Weeks(Calendar Date)' in the drop down. For the value to be right, I created
Num weeks = DISTINCTCOUNT(DimDate[CalendarWeekOfYear])
Num weeks works fine only when 'Weeks(Calendar Date)' is selected. I am trying to retrieve the parameter passed to the slicer to get my values right.(whether the user selects 'Weeks(Calendar Date)' or 'Weeks' in the slicer).Is there a way to retrieve this or
Is there a way to combine these two?
If you have a slicer like with Weeks (Calendar Date) and Weeks as the two options in the column Slicer[WeekType], then you can pass your selection into a measure like this:
Weeks =
VAR WeekType = SELECTEDVALUE(Slicer[WeekType], <default>)
RETURN IF(WeekType = "Weeks", [Tot Weeks], [Num weeks])