Custom calculation for visualization - powerbi

I am looking to create a custom calculation for a visualization in Power BI. In particular, I am looking to get a weighted average of my data.
My data set looks something like this:
Cluster Name | Node | Call Name | Errors | Calls
I would like to make a dashboard where I'm giving the percent error over time based on filters on the level of Cluster Name, Node, Call Name, or some combination of these. (The cluster name being the most broad and the call name being the least broad.)
I can easily set up a SQL query that gives me the percent error for each of these categories by doing SUM(Errors)/Sum(Calls) grouped by the category used and this is what I would like to replicate in my visualization.
The reason why I cannot simply calculate the percent error for the broader categories by taking an average of the simpler categories is that not every Call Name has an equal number of Calls. Therefore, I have to use a weighted average or simply recalculate SUM(Errors)/Sum(Calls) for each category selection.
I have tried to accomplish this using a custom column using DAX, but the numbers that the column calculates make no sense. My formula is PercentError = DIVIDE(MyTable[Errors], MyTable[Calls],0)*100, but the calculation seems to give really off numbers. For example, one row has 45 errors and 48 calls, but the percent error is listed as 2630.
Is there a way to do this through the visualization and/or the custom column calculations?

You can do this using a calculated measure rather than a calculated column. The formula would be exactly what you have described in your post
=SUM(Table[Errors])/SUM(Table[Calls])
Format as a % in the Modelling tab and voila.
Put your new measure in the values of a visual like a Matrix and put whatever columns you want to slice and dice this by in the Rows or Columns.

Related

Use NOM.DIST with filters in PowerBI

I would like to create a measure that allows me to study the distribution of a certain dataset depending on the filters applied.
I have a dataset that has multiple categories. My objective here would be to create a histogram inside each specific category to check whether all different categories follow a normal distribution. However, I have only been able to calculate the normal distribution by creating a new column with the following formula:
DistributionCurve_Disassembly = NORM.DIST('also'[01.Disassembly],AVERAGE('also'[01.Disassembly]),STDEV.P('also'[01.Disassembly]),false)
The problem with that is that it calculates the distribution by taking all the rows, without separating them by categories. Therefore, I would like to create a measure that calculates itself every time depending on the selected filters.
PD: 'also'[01.Disassembly] is the column where all the hours that will be calculated as distribution are shown and it would be filtered by two columns called 'also'[IB Bowl] and 'also'[application]

Quicksight - how to show aggregated value as Fraction

I am creating a pivot table in quicksight, one of the rows I want to calculate the average so I have applied avaerage option on it. It aggregates it up to the root level 500/6 = 83.333 so far so good.
Now I want to tweak this a bit and instead of showing 83.333, I want to show it as fraction value like 5/6, it basically denotes 5 are passed out of 6. How I can achive the same ?
Unfortunately, as far as I know, QuickSight doesn't provide any such functionality out of the box. What you can do instead is get a total count of all the objects in the table and another count of the items that have passed and then display them one after another.

Calculate % of two columns Power BI

I want to calculate % of two columns which are already in %.
I want to calculate formula like
Target achieved= ACTUAL/TARGET
But here is ACTUAL is already a measure/calculated metrics so I'm not able to divide these two columns.
Any help would be appreciated..
Make sure both target and actual are actually numbers and not strings. You can do it in transform data (aka Power Query) part, before data is loaded into the report.
After that you should be able to create the measure you want, e.g. something like that:
UPDATE : What happens if Actual is not a column, but a measure?
If Actual measure is based on the columns in the same table as target you shouldn't have a problem. You cannot combine measure and column in the same formula. Measure is an aggregated field and needs to be grouped by another field (if you are familiar with SQL,think of SUM and GROUP BY). Coming back to your problem, you need to create measure out of "Target" column as well (notice I have in the formula SUM('Table'[Plan]) which makes it a measure). Than you can use both of them in the formula, but of course you need to "group" them by something(e.g. date) otherwise it will just show you a total.

Can't find DAX function to correctly calculate Sum

I run a simple query in SQL:
select count(*) FROM Abattoir.RecordScan_BloodPit
JOIN Abattoir.RecordScan RS ON RS.ScanId = RecordScan_BloodPit.ScanId
WHERE rs.HarvestDate = '07/16/2018'
which gives me a correct number of rows (say 2000)
I then go to my measure editor in Power BI, and enter:
CALCULATE(COUNT(BloodPit[ScanId]))
and get an insane number of around 254000000.
I don't understand why counting on a field so simply would give me a completely Different number.
New to DAX so my Google strings might not be the best when conducting searches.
Here is what the report looks like. Please note the nubers inside the rectangle are what I'm trying to calculate. The numbers vary from day to day...

Measure to sum another aggregated measure's data

I am working on a report that has data by month. I have created a measure that will calculate a cost per unit which divides the sum of dollars by the sum of production volume for the selected month(s):
Wtd Avg = SUM('GLData - Excel'[Amount])/SUM('GLData - Excel'[Production])
This works well and gives me the weighted average that I need per report category regardless of if I have one or multiple months selected. This actual and budget data is displayed below:
If you take time to total the actual costs you get $3.180. Where I am running into trouble is a measure to sum up to that total for a visual (This visual does not total sadly). Basically I need to sum the aggregated values that we see above. If I use the Wtd Avg measure I get the average for the total data set, or .53. I have attempted another measure, but am not coming up with the correct answer:
Total Per Unit Cost = sumX('GLData - Excel','GLData - Excel'[Wtd Avg])/DISTINCTCOUNT('GLData - Excel'[Date])
We see here I return $3.186. It is close, but it is not aggregating the right way to get exactly the $3.180:
My Total Per Unit Cost formula is off. Really I am simply interested in a measure to sum the post aggregated Wtd Avg measure we see in the first graph and total to $3.180 in this example.
Here is my data table:
As you probably know already, this is happening because measures are dynamic - if you are not grouping by a dimension, they will compute based on the overall table. What you want to do is to force a grouping on your categories, and then compute the sum of the measure for each category.
There are 2 ways to do this. One way is to create a new table in Power BI (Modeling tab -> New Table), and then use a SUMMARIZE() calculation similar to this one to define that table:
SUMMARIZE('GLData - Excel',[Category],[Month],[Actual/Budget],"Wtd Avg",[Wtd Avg])
Unfortunately I do not know your exact column names, so you will need to adjust this calculation to your context. Once your new table is created, you can use the values from that table to create your aggregate visual - in order to get the slicers to work, you may need to join this new table to your original table through the "Manage Relationships" option.
The second way to do this is via the same calculation, but without having to create a new table. This may be less of a hassle. Create a measure like this:
SUMX(SUMMARIZE('GLData - Excel',[Category],[Month],[Actual/Budget],"Wtd Avg",[Wtd Avg]),[Wtd Avg])
If this does not solve your issue, go ahead and show me a screenshot of your table and I may be able to help further.