filtering using Rank() and Index() not changing the total - tableau-api

I am calculating efficiency for mechanics using the sum of hours worked divided by the sum of hours we charged the customer as per work order. Using tableau's total from the analytics pane, it gives me the weighted average of their efficiency (whereas the average function is skewed as it only takes into account the final efficiency rating.
When I use index() or rank() to create a filter to remove individual work orders, the total doesn't change.
How can I remove work orders and change the total without having to use a filter that selects individual work orders?

You could try using LOD with specific condition in the if statement before you take the average or do any calculation.
Since the fixed calculation will take the data directly from the table. The number will only changed with filter when you put the parameter in the first part of LOD.
A quick example:
{Fixed [parameter]: AVG(IF [work orders] == condition then [weighted average] END)}

Related

How to compare two averages for the same column?

I want to take an average of the whole data and then filter that data and take another average and then compare the two. Any help is appreciated.
Translating on sample superstore-
The following expression will give average of sales for entire data
{ Avg([sales])}
across all rows. The following expression will, however, give category wise average sales
{FIXED [Category]: avg([sales])}
across all rows again. If you want to apply filters on these calculations add that filter to context but be cautious that the filters will then filter the data used for calculations in both the expressions. If you just want to filter data for viewing purpose and not the calculations dont add the filters to context.

Sum of calculated averages PowerBI

I'm fairly new to PowerBI, I want to calculate sum of averages as measure.
So average is perfectly fine but I couldn't manage to sum them.
average = AVERAGEX(SUMMARIZE(ProductionVolumeData,
ProductionVolumeData[ProductionOrderID],
MDCProductionVolumeData[MachineID],
"sum_volume",
SUM(ProductionVolumeData[Volume])),[sum_volume])
this formula calculates aggregates volume group by production order id and machine id and find mean.
I checked in table, it works for one ProductionOrderID but whenever I add another ProductionOrderID to table it also calculates average. What I want is to sum up averages.
How can I do that?
Thanks in advance

Power BI: Finding average of averages and STDEV.P of averages

All,
My overall objective is to find outliers within an aggregated data set vs the underlying detail for different date ranges. The issue I am having is that Power BI is averaging the SalesPerDay and finding the STDEV.P at the daily level which is the grain of the raw data. I need to first find the average Sales, then find the average of those averages for that "rolled up" data set. Same with STDEV.P. Need to find the STDEV of the "rolled up" averages. Screenshot below depicting how I need the tool to aggregate.
I have brought the Sales column into my dashboard, dimentionalized by user, and set to AVERAGE to get average SalesPerDay.
Then I created the new measure
newavg = CALCULATE(AVERAGE(SalesPerDay[Sales]),ALLSELECTED())
Which is finding the overall average, but at the daily level vs the aggregated level.
I also tried
newSTDV = CALCULATE(STDEV.P(AVERAGE(SalesPerDay[Sales])),ALLSELECTED())
But you cannot find the STDEV.P of a calculation.
Thank you.
What you are looking for is the iterator functions, which take a table or column of data as a grouping, and then applies a calculation on that group.
Example of one would be SUMX. In the example below, it would do a grouping based on Product. Within each product it would get the total of qty and multiply it by the sum of x. It would then sum the results of that calculation into a total.
SUMX( VALUES( table1 [ Product ] ), [Qty] * [x] )
There also being averagex, minx, maxx, plus for the statistical functions there is STDEVX.P and STDEVX.S

Why window_avg in tableau has to work on aggregated variable?

I am trying to calculate a rolling average by 30 days. However, in Tableau, I have to use window_avg(avg(varaible), - 30, 0). It means that it is actually calculating the average of daily average. It first calculate the average value per day, then average the values for past 30 days. I am wondering whether there is a function in Tableau that can calculate directly rolling average, like pandas.rolling?
In this specific case, you can use the following
window_sum(sum(variable), -30, 0) / window_sum(sum(1), -30, 0)
A few concepts about table calcs to keep in mind
Table calcs operate on aggregate query results.
This gives you flexibility - you can partition the table of query results in many ways, access multiple values in the result set, order the query results to impact your calculations, nest table calcs in different ways.
This approach can also give you efficiency if you can calculate what you need simply from the aggregate results that you've already fetched.
It also gives you complexity. You have to be aware of how each calculation specifies the addressing and partitioning of the query results. You also have to think about how double aggregation will impact your results.
In most cases, applying back to back aggregation functions requires some careful thought about what the results will mean. As you've noted, averages of averages may not mean what people think they mean. Others, may be quite reasonable, say averages of daily sales totals.
In some cases, double aggregation can be used without extra thought as the results are the same regardless. Sums of Sums, Mins of Mins, Max of Max yield the same result as calling Sum, min or max on the underlying data rows. These functions are called additive aggregation functions, and obey the associative rule you learned in grade school. Hence, the formula at the start of this answer.
You can also read about the Total() function.

Tableau calculation: I am trying to calculate the percentage of running sum but am unable to create a calculation

I am trying to calculate number of customers which represent 80% of the profit so that I can use it in a calculated field which I can use in a reference line.
This is what I wrote
IIF(RUNNING_SUM([Profit])= (0.8*SUM([Profit])),
COUNTD([Customer Name]),0)
but it gives me error saying
"All fields must be constant or aggregate when using table calculation functions"
The logic is to "Count distinct number of customers which represent 80% of running total profits"
This is meant for a pareto chart, so the values are already sorted in descending order for it to work.
How do I create such calculated field which would give me number of top customers which will represent 80% of the profits?
Let me know if more clarifications are needed.
I think you are looking for a Pareto Chart. This might help:
http://www.theinformationlab.co.uk/2014/08/27/pareto-charts-tableau/
I would leverage the power of Table Calculations, where you can first do running total of profit and then simply calculate percentage of total.
Here is the link to step-by-step tutorial in Tableau10 for Pareto Analysis (80/20 rule):
https://www.tableau.com/learn/tutorials/on-demand/pareto-charts?signin=15df68b66e703787258911e79db040a7.
Hope this helps.