Power BI: how to remove top 20% of values from an average - powerbi

I'm working with call center data and looking to calculate the average ring time of calls while removing the highest 20% of ring times. I assume I'll need to use PERCENTILEX.EXC embedded somewhere in AVERAGE, but I'm not quite sure where, or if I'm totally off base. 2 other caveats on this are that there are calls answered immediately (queue time = 0) which have to be counted in the average time and only data where the disposition column = Handled are used.
Example:
The Aborted and Abandoned call would be filtered out. Of the remaining calls, the top 20% of queue times (the 14,9, 6, and one of the 5s) would be eliminated and the average would be 3 seconds.
Appreciate any help on this!

I would do it like this:
VAR totalRows = COUNTROWS(FILTER(table, table[disposition] = "Handled"))
VAR bottomN = ROUNDDOWN(totalRows * .8, 0)
RETURN AVERAGEX(TOPN(bottomN, FILTER(table, table[disposition] = "Handled"), table[queue time], ASC),table[queue time])

Related

Dax - Reverse margin calculation on a slider slicer

I have a measure that calculates the reverse margin following this principle:
RMS=C/(1−(MP/100))
Where RMS is the Reverse Margin Sell Price (£)
C is the cost of the product (£)
MP is the margin percentage (%)
The DAX measure itself looks like this:
_rms20% =
VAR newGP = DIVIDE([_cost], (1-20/100))
RETURN
IF([_%currentGP]>0.2, BLANK(), newGP)
So if the current GP percentage is higher than 20% blank space is returned, if it is lower I have the RMS calculation returned.
This works nicely but problem occurs when I create a "What-IF" parameter slider as follows:
Increase = GENERATESERIES(0, 100, 1)
Increase Value = SELECTEDVALUE('Increase'[Increase])
and use this parameter with the RMS measure:
_slider% = [_rms20%] * (100+'Increase'[Increase Value])/100
For example if my Cost is £27.26 and desired gp is 20% than cost has to be increased to £34.08 - this is done by the basic calculation following the principle mentioned above.
If I put this on a slider and increase it by 5 to 25% the value it shows is £35.78 while in fact it should be £36.34.
I have been trying to fix this for some time now so any advice/recommendation would be very appreciated.

Planning subsequent orders

Let's say I have 5 orders and 3 drivers. I want to maximize the amount of miles they have on the road. Each driver has times that they're available to drive and orders have times that they're able to be picked up at.
Ideally, I would like to be able to plan subsequent orders in one go, rather than writing multiple models at once. My current iteration is to write multiple models that give output and subsequent models take those as inputs. How can you write this as a singular LP model?
O = {Order1, Order2, Order3, Order4, Order5}
D = {Driver1, Driver2, Driver3}
O_avail = {2 pm, 3pm, 230 pm, 8pm, 9pm, 12 am}
D_avail = {2pm, 3pm, 230pm}
Time_to_depot = {7 hours,5 hours,2 hours,5 hours,3hours, 4hours}
constraints
d_avail <= o_avail
obj function
max sum D_i*time_to_depot_i
I laid it out in such a way that driver 1 takes order 1, order 5 and order6. Driver 2 takes order 2 and order 4.

Power BI Count the total count of columns that contain a "2"

I was able to find the “2”'s per client with the following formula (Column L).
TotalSimultaneous2 =
IF(Data[Column1]=2,1,0)+
IF(Data[Column2]=2,1,0)+
IF(Data[Column3]=2,1,0)+
IF(Data[Column4]=2,1,0)+
IF(Data[Column5]=2,1,0)+
IF(Data[Column6]=2,1,0)+
IF(Data[Column7]=2,1,0)+
IF(Data[Column8]=2,1,0)+
IF(Data[Column9]=2,1,0)+
IF(Data[Column10]=2,1,0)
Now I need help finding the total amount of columns that contain at least one “2” column N.
In the example below, it would be 7, and that number is coming from the count of all the columns in green since they have at least one “2”.
I can find the simultaneous one. For example, Client4 has the max amount of “2” at the same time, which is 6, but I am having a hard time adding that one “2” from Column10 from Client10 and showing that the number of columns containing a “2” is 7 instead of 6.
Anything helps. Feel free to ask for further clarification, and I will try my best.
You can try this below measure. Here I have added 3 columns but you can add as many as you have-
count_column_with_2 =
CALCULATE(
DISTINCTCOUNT(your_table_name[col1]),
FILTER(your_table_name, your_table_name[col1] = 2)
)
+
CALCULATE(
DISTINCTCOUNT(your_table_name[col2]),
FILTER(your_table_name, your_table_name[col2] = 2)
)
+
CALCULATE(
DISTINCTCOUNT(your_table_name[col3]),
FILTER(your_table_name, your_table_name[col3] = 2)
)

Power BI - "Other" Classfication Based on Percentage of Total

quick question:
I have a total amount that is divided into several classifications, like so:
Total: 7bn
Classification 1: 3bn,
Classification 2: 1bn,
... ,
Classification N: 0,3M
N is such a big number that when I put in a graph, most of the classifications don't even show up in there, so my manager suggested that I took anything that represents less than 5% of the total 7bn and classified them as "Others" to put it all together in the visual.
Then I made a measure "% of total" like:
% of total =
divide(
sum(values),
sumx(
allselected(table),
values
)
)
And this actually works perfect, except...
I wanna make a measure (or calculated column) that returns something like:
new classification =
if(
[% of total] > 0.05,
"Others",
[classification]
)
just to classify for me in the graph
but then only one of the new classifications returns as the old one, the rest returns "Others", but I know there's more than one, according to [% of total].
Can you think of another way to make this work? Is this a dumb question?
Thanks in advance
Create 2 separate measure for [others] & [classification] and create your final measure as below-
new classification =
var is_greater = IF([% of total] > 0.05, 1, 0)
RETURN
SWITCH(
is_greater ,
1,[Others]",
[classification]
)

how to find time band using dax in power bi?

I would like to find time band of half hour.Suppose i have a time stamp :
2019-03-12 01:20:00 this exists between time band of 1:00-1:30, similarly
2019-03-12 04:33:00 this exists between time band of 4:30-5:00.
I have column of n number of timestamp.
Is there any dax function that i can write to find the time band or there is any other process?
Thanks in advance!!
Consider something like this:
TimeBand =
FORMAT(FLOOR(MyTable[Timestamp], 1/48),"h:mm")
& " - "
& FORMAT(CEILING(MyTable[Timestamp], 1/48),"h:mm")
Floor and Ceiling are very similar functions -- they essentially round to the nearest multiple. Floor picks the biggest multiple that is smaller, and ceiling picks the smallest multiple that is bigger. Usually we round to powers of 10, but with this function we can round to the nearest 5, or 7, or 1/3.
Combine this with the understanding that PowerBI values all datetimes as a special kind of number -- it is simply the count of days since 12/30/1899. (Try it, create a calculated column and set its value to 0, then display it as a date time). So in this system "1" is one day. That means 1/24 is one hour, and 1/24/60 is one minute. It follows, then, that 30/24/60 is 30 minutes, and that reduces to 1/48.
So now we can take Floor/Ceiling, give it a time, and have it round that datetime to the nearest half-hour -- either down or up depending on which function you choose.
Use format to convert everything to text, and you're all set.
Here's some sample data generated in Power Query:
let
Source = List.Generate(()=> #datetime(2020,3,1,0,0,0), each _ < #datetime(2020,3,1,0,0,0) + #duration(1,0,0,0) , each _ + #duration(0,0,5,0)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Timestamp"}, null, ExtraValues.Error)
in
#"Converted to Table"
And the results of our DAX:
Hope it Helps!