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

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

Related

Circular dependency while calculating column

I have a single table of data named RDSLPDSL. I am trying to calculate two columns based on two measures I am creating from the table.
Count of RDSL Marker for 1 =
CALCULATE(
COUNT('RDSLPDSL'[RDSL Marker]),
'RDSLPDSL'[RDSL Marker] IN { 1 }
)
I am using the above code as a measure to look for values only with 1 in it in the RDSL Marker column.
RDSL % = DIVIDE([Count of RDSL Marker for 1], COUNTROWS(RDSLPDSL))
Then I created a column using the above code to divide the rows with 1 by the total number of rows in the table.
I am doing the same for another column with PDSL. It is as follows:
Count of PDSL Marker for 1 =
CALCULATE(
COUNT('RDSLPDSL'[PDSL Marker]),
'RDSLPDSL'[PDSL Marker] IN { 1 }
)
PDSL % = DIVIDE([Count of PDSL Marker for 1], COUNTROWS(RDSLPDSL))
But when I do this calculation, I am getting an error for circular dependency detected and not getting the final output even though the same code worked for the previous column.
I tried COUNTAX directly instead of using CALCULATE but that brings up the same error too.
I also tried using measures instead of custom column which seems to remove the error but the output is not what I expect and is incorrect.
Any help for the same would be highly appreciated.

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

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

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!

How to to solve divide by zero error (NaN - Not a Number) in my formula in Power BI?

I have a column with a formula which reads:
Utilisation (Excl. Time-off) = Utilisation_Excl_Timeoff[Billable Hours]/(Utilisation_Excl_Timeoff[Available Hours] - Utilisation_Excl_Timeoff[Timeoff Hours (Excl. Public)])
It gives me a "NaN" error in my calculated column for some of the cells due to divide by zero.
I would like to replace the NaN with a 0% instead so that the column displays correctly in my matrix chart.
Take a look at the DIVIDE function (https://msdn.microsoft.com/en-us/library/jj677276.aspx).
This is a 'safe divide` function with the option to return an alternative value if the division returns an error.
-JP
If you are looking for solution in M, then add conditional column:
Set up Otherwise temporarily to dividend column, here I took [Value] column. After doing this change in editor [Value] to [Value]/[Units]. This returns null wherever Units is 0. You may change returned output to 0% according to thy wish.
Alternatively, you can do it as well by adding this step:
= Table.AddColumn(#"Previous Step", "UnitPrice", each if [Units] = 0 then "0%" else [Value]/[Units])
IFERROR(value, value_if_error) function can do this. MSDN
Utilisation (Excl. Time-off) = IFERROR(Utilisation_Excl_Timeoff[Billable Hours]/(Utilisation_Excl_Timeoff[Available Hours] - Utilisation_Excl_Timeoff[Timeoff Hours (Excl. Public)]), 0)