Show total Minute Utilization for An hour in PowerBI report - powerbi

I am trying to do log(ssrs execution log) analysis is powerbi. Requirement here is to show how many minutes utilized for a particular hour based on the request start & end time. Below is example for 4 requests Start & end time with expected result.
1st request 12:00 AM - 12:15 AM
2nd request 12:05 AM - 12:10 AM
3rd request 12:40 AM - 12:42 AM
4th request 12:41 AM - 12:48 AM
So total minute utilization for 12 AM hour should be 15mins(as first two requests overlap with each other) + 8mins (as last two also overlap for some mins) = 23 mins of total utilization at 12 AM.
Any help will be greatly appreciated.

I'd recommend splitting up the hour into 60 minutes and counting how many of the minutes are within the time frame of one of the requests.
Something like this logic for a calculated column:
Utilization =
VAR CurrentHour = HOUR ( Requests[Start] )
VAR Minutes =
GENERATESERIES (
TIME ( CurrentHour, 0, 0 ),
TIME ( CurrentHour + 1, 0, 0 ),
TIME ( 0, 1, 0 )
) /*This generates a column named [Value] with 61 rows
starting from the beginning of the hour.*/
RETURN
SUMX (
Minutes,
IF (
COUNTROWS (
FILTER (
Requests,
HOUR ( Requests[Start] ) = CurrentHour
&& Requests[Start] < [Value]
&& Requests[End] > [Value]
)
) > 0,
1,
0
)
)

Related

Powerbi: How to calculate average value per hour from value in minutes?

So I am building a report that shows the time spent on a job and the income the job has generated. My boss wants to see the average income of a job in hours.
Let's say three jobs have been completed:
Job A: Time: 12 minutes & income 450 euro
Job B: Time: 24 minutes & income 600 euro
Job C: Time: 38 minutes & income 950 euro
Job D: Time: 82 minutes & income 1800 euro
How do i calculate the average income per hour in PowerBI/DAX?
If you want to do it in a structured way:
DEFINE
TABLE Payroll = SELECTCOLUMNS ({
("Job-A",FORMAT(TIME(00,12,00),"HH:MM:SS"),450),
("Job-B",FORMAT(TIME(00,24,00),"HH:MM:SS"),600),
("Job-C",FORMAT(TIME(00,38,00),"HH:MM:SS"),950),
("Job-D",FORMAT(TIME(00,82,00),"HH:MM:SS"),1800)
},"Type",[Value1],"Duration",[Value2],"Income",[Value3])
EVALUATE
Payroll
Final Code:
EVALUATE
ROW (
"AVG_Earnings",
FORMAT (
ROUND (
AVERAGEX (
ADDCOLUMNS (
ADDCOLUMNS (
Payroll,
"Hour", HOUR ( Payroll[Duration] ),
"Minute", MINUTE ( Payroll[Duration] ),
"Seconds", SECOND ( Payroll[Duration] )
),
"Total",
ROUND ( [Hour] + DIVIDE ( [Minute], 60 ) + DIVIDE ( [Seconds], 3600 ), 4 )
),
DIVIDE ( [Income], [Total] )
),
2
),
"Currency",
"de-DE"
)
)

PowerBI calculate overflow backlog in measure

My data is as follows:
Factory ID
Week
CAPACITY
Request
1
21
1000
500
1
22
1000
1200
1
23
1500
1600
1
24
1500
1100
2
21
1000
500
2
22
2000
1900
2
23
2000
1000
2
24
2000
2500
3
21
1000
200
3
22
1000
900
3
23
1000
1300
3
24
1000
800
I want to calculate backlog in a measure or any other way to have backlog be dynamic based on the factories I select. Backlog is calculated as follows:
Backlog = Capacity - (Request + Previous week backlog); where we have backlog when requests + pre. week backlog exceeds capacity or else it is 0. I cannot move capacity from future weeks, so the backlog would always accumulate going forward
Eg. If I select Factory 1, my backlog should look as follows:
Factory Selected: 1
Week
Backlog
21
0
22
-200
23
-300
24
-100
Factory Selected: 1,2
Week
Backlog
21
0
22
-100
23
0
24
-400
Factory Selected: 1,3
Week
Backlog
21
0
22
-100
23
-500
24
0
I have been trying to find a solution since the last 2 days. Let me know if you need any additional details. Any help will be greatly appreciated.
In DAX there are no loops and no recursion, this means that we must write some very ugly loop unrolling dax code. This is a minimal implementation of a working measure, but to make it working in the general case the BacklogWeekNN variables must be added until reaching the maximum possible week depth in the model.
Backlog =
VAR MinWeek = CALCULATE(MIN( T[Week] ), REMOVEFILTERS( T ) )
VAR MaxWeek = MAX( T[Week] )
VAR TAggregated =
ADDCOLUMNS(
CALCULATETABLE( VALUES( T[Week] ), T[Week] <= MaxWeek, REMOVEFILTERS( T ) ),
"#Capacity", CALCULATE( SUM( T[CAPACITY] ), ALLEXCEPT( T, T[Week], T[Factory ID] ) ),
"#Request", CALCULATE( SUM( T[Request] ), ALLEXCEPT( T, T[Week], T[Factory ID] ) )
)
VAR BacklogWeek00 = SUMX( FILTER( TAggregated, T[Week] = MinWeek ), [#Capacity] - [#Request] ) + 0
VAR BacklogWeek01 = SUMX( FILTER( TAggregated, T[Week] = MinWeek + 1), [#Capacity] - [#Request] ) + IF(BacklogWeek00 > 0, 0, BacklogWeek00)
VAR BacklogWeek02 = SUMX( FILTER( TAggregated, T[Week] = MinWeek + 2), [#Capacity] - [#Request] ) + IF(BacklogWeek01 > 0, 0, BacklogWeek01)
VAR BacklogWeek03 = SUMX( FILTER( TAggregated, T[Week] = MinWeek + 3), [#Capacity] - [#Request] ) + IF(BacklogWeek02 > 0, 0, BacklogWeek02)
VAR Result = IF(BacklogWeek03 > 0, 0, BacklogWeek03)
RETURN Result
This way we can obtain the desired resulting matrix using a slicer to select the factories (I'm afraid there are a few errors in the expected result samples int the question)
Edit: I used 'FILTER( TAggregated, T[Week] = MinWeek )' instead of the equivalent CALCULATE/CALCULATTABLE DAX code to avoid context transition happening and because the weeks table has very few rows to be iterated (I can imagine a maximum of a few tens or at maximum hundreds of rows if keeping a few years history)

Determining a Style Changeover by Machine using PowerBI

So I have a table that has the output of all machines in a department with styles. For example:
|Machine| |Style| | QTY| |Time| |Date| etc...
1 001 100 8:00AM 5/21/19
2 001 200 8:05AM 5/21/19
1 001 100 9:00AM 5/21/19
1 004 100 10:00AM 5/21/19
2 001 200 9:05AM 5/21/19
I'm looking to see the amount of times a style is changed for a machine. So in this case, for Machine 1 it was one style change and for Machine 2 it was zero.
I've tried adapting some code to no avail; mainly because I'm having trouble understanding the logic and I can't really think of a good index to work with.
Here is what I got so far:
EarliestChange Over Index =
VAR Temp =
CALCULATE (
MAX ( Table[Index] ),
FILTER (
Table,
[Index] < EARLIER ( [Index] )
&& [Style] <> EARLIER ( [Style])
&& Table[Date] = today()-1
)
)
VAR Temp1 =
CALCULATE (
MIN ( [Index] ),
FILTER (
Table,
[Index] > EARLIER ( [Index] )
&& [Style] <> EARLIER ( [Style])
&& Table[Date] = today()-1
)
)
RETURN
IF ( [Index] > temp && OR ( [Index] < temp1, ISBLANK ( temp1 ) ), temp + 1, 0 )
I tried to restrict it to just one day so that I could evaluate the results so that portion can be dropped. I've tried two different indexes, one was the machine number and the other was the difference in time from today and the min date on the table. In a visual, I've been taking a distinct count of the EarliestChange Over Index and subtracted one since it didn't constitute a "change over."
EDIT:
Issue where multiple styles are logged at the same time causing false change overs.
|Machine| |Style| | QTY| |Time| |Date| etc...
1 001 100 8:00AM 5/21/19
1 001 100 9:00AM 5/21/19
1 004 100 10:00AM 5/21/19
1 004 100 10:00AM 5/21/19
1 004 100 10:00AM 5/21/19
In one department a time would never be duplicated. However, in another department (for whatever reason) might log 3 rolls at the same time. This would cause the equation to log 10:00am as 3 change overs. It might be a system glitch why there isn't unique time stamps per roll but this is the case unfortunately.
One way of doing it:
First, I modified your data as follows:
Added a record for Machine 1 at 11:00AM to capture a situation when a style reverts to the old one;
Added a column for Date-Time (simply Date + Time), to make life easier;
Named the table as "Data"
Measure:
Style Change Count
=
SUMX (
Data,
VAR Current_DateTime = Data[Date-Time]
VAR Current_Style = Data[Style]
VAR Previous_DateTime =
CALCULATE (
MAX ( Data[Date-Time] ),
FILTER ( ALLEXCEPT ( Data, Data[Machine] ), Data[Date-Time] < Current_DateTime )
)
VAR Previous_Style =
CALCULATE (
VALUES ( Data[Style] ),
FILTER ( ALLEXCEPT ( Data, Data[Machine] ), Data[Date-Time] = Previous_DateTime )
)
RETURN
IF ( Current_Style = Previous_Style || ISBLANK ( Previous_Style ), 0, 1 )
)
Result:
How it works:
We need to use SUMX to make sure that our subtotals and totals are correct;
SUMX iterates over Data table and for each record computes "Previous date-time", which is simply the max datetime less than the current datatime, per machine (hence ALLEXCEPT);
Then, we can calculate Previous Style, which is a style where date-time = previous date-time;
Finally, we compare current style and previous style. If they are not the same, we add 1;
In addition, I added a test for the starting condition - first occurrence of a machine, for which previous style does not exist yet. I did not treat such records as "style change". If you want to count initial records as style change, remove ISBLANK() part.

Time bucket in power bi

Time bucket
column dax query:
Column = if(Table1[TransactionDate].[Date]=Table1[COBProcessDate].[Date],
SWITCH (
TRUE (),
HOUR ( Table1[COBProcessDate] )
+ MINUTE ( Table1[COBProcessDate]) / 60
>= 6
&& HOUR ( Table1[COBProcessDate] )
+ MINUTE ( Table1[COBProcessDate] ) / 60
< 8.5, "6:00 a.m. - 8:30 a.m.",
HOUR ( Table1[COBProcessDate])
+ MINUTE ( Table1[COBProcessDate]) / 60
>= 8.5
&& HOUR ( Table1[COBProcessDate])
+ MINUTE ( Table1[COBProcessDate]) / 60
< 9.5, "8:30 a.m. - 9:30 a.m",
HOUR ( Table1[COBProcessDate].[Date] )
+ MINUTE ( Table1[COBProcessDate]) / 60
>= 9.5
&& HOUR ( Table1[COBProcessDate])
+ MINUTE ( Table1[COBProcessDate] ) / 60
< 12, "9:30 a.m. to noon",
HOUR ( Table1[COBProcessDate] )
+ MINUTE ( Table1[COBProcessDate] ) / 60
>= 12
&& HOUR ( Table1[COBProcessDate])
+ MINUTE ( Table1[COBProcessDate]) / 60
< 15.5, "noon to 3:30 p.m.",
HOUR ( Table1[COBProcessDate].[Date] )
+ MINUTE ( Table1[COBProcessDate] ) / 60
>= 15.5
&& HOUR ( Table1[COBProcessDate] )
+ MINUTE ( Table1[COBProcessDate] ) / 60
< 18, "3:30 p.m. to 6:00 p.m.",
"6:00 p.m. - 6:00 a.m."),"Next Day")
I am not able to arrange time in correct series . like 6:30a.m-8:30a.m then 8:30a.m to 9:30a.m then noon to 6:30p.m then 6:30pm to 11:59 pm then next day.
screen shot is attached.
thanks in advance.
by default the column values are alphabetically ordered, if you want or have to change this, you have to complete the following steps:
Create another calculated column "column index"
The column values will be used to order the column values of your 1st column.
The result will look something like this
... | column | column index
... | 6:00 a.m. - 8:30 a.m. | 1
... | 8:30 a.m. - 9:30 a.m. | 2
...
You can use the exact same DAX formula, but instead returning a string you will return a numeric value that represents the sort index
Sort "Column" by "Sort Column"
In the "Data-View" mark the column you want to order, switch to the "Modeling" ribbon and select "Sort by Column" - select the column that contains the numeric values.
Hide the index column
To avoid clutter in the Fields pane I always hide my index columns.
Hopefully this is what you are looking for
Regards
Tom

Changing Average of Seconds in minutes and seconds

I have a table below:
I am trying to get the average of "someNumber" (which is number of seconds) per date and then convert that number into miutes and seconds.
So, I am drawing the graph below:
As you can see, I used the average filter and it calculated the average of "someNumber" per date. For instance, the average on 1st is 13. Now, how do I convert 13 into minutes and seconds so that I can display it as a tooltip?
Create a measure to get the average in seconds.
avg = AVERAGE(Table[SomeNumber])
Then create a measure for the tooltip lets call it Time, this helpful measure was created by #konstantinos and #smoupre in the Power BI community blog.
Time =
VAR Duration = [avg] // Here use the average measure created before
VAR Hours =
INT ( Duration / 3600)
VAR Minutes =
INT ( MOD( Duration - ( Hours * 3600 ),3600 ) / 60)
VAR Seconds =
ROUNDUP(MOD ( MOD( Duration - ( Hours * 3600 ),3600 ), 60 ),0)
VAR H =
IF ( LEN ( Hours ) = 1,
CONCATENATE ( "0", Hours ),
CONCATENATE ( "", Hours )
)
VAR M =
IF (
LEN ( Minutes ) = 1,
CONCATENATE ( "0", Minutes ),
CONCATENATE ( "", Minutes )
)
VAR S =
IF (
LEN ( Seconds ) = 1,
CONCATENATE ( "0", Seconds ),
CONCATENATE ( "", Seconds )
)
RETURN
CONCATENATE ( M, CONCATENATE ( ":", S ) )
Now use the [Time] measure as tooltip in your chart
Hope it helps.