Sum of calculated averages PowerBI - group-by

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

Related

Tableau Weighted Average of Last Value in Date Group over Running Sum Across Extra Level of Detail not in Report

I am an absolute Tableau beginner, so forgive my lack of proper terminology.
Context
To give some context to the problem, think of the dataset as the balances and current interest rates of two different loans for which we are trying to calculate a weighted average cost of funds at any point in time, while retaining the ability to filter on Program (specific loan).
I have a single dataset that looks like:
The Balance field is used as a running sum, i.e. to get the actual balance as of 4/30/2022, you would sum the column across all Date values on or before 4/30/2022.
The Rate field is the opposite: it represents the discrete interest rate as of the Date. Thus, it cannot be summed.
Each data point is specific to a specific loan, or Program.
So to get the interest rate of Program A as of 4/30/2022, you would simply grab the Rate value of the row where Date = 4/30/2022 and Program = A, or 5.30%. Sums are fine here, since the value of Rate is never repeated for a single Program and Date combo, but we cannot use a running sum.
On the other hand, to get the balance of Program A as of 4/30/2022, you would need to add (running sum) the Balance values for all rows where Date <= 4/30/2022 and Program = A, or 10,000 + -2500 + -2500 + -2500 = 2500.
Problem / Need
I need a report (or whatever it's called in Tableau) with the following:
Date as a column
Measures as rows
This report would NOT include Program as a row or column, but would include it as a filter.
In this report, I need a Weighted Average Cost of Funds measure.
This is effectively the weighted average Rate over/weighted by the running sum of Balance across Programs included in the filter, of course for any given Date in the columns.
In other words, by Date, latest Ratefor eachProgramtimes thePrograms running sum of Balance, divided by running sum of all Balancesfor allProgram`s included in filter.
Here's an example in Excel:
Here's an example if we were to exclude Program A:
And here's an example if we were to exclude Program B:
Finally, here's the formulas underneath everything in the Excel example:

My DAX code to calculate a moving average is not giving the correct result

I'm hoping that someone can help me. I'm wracking my brain on this and just cannot get my moving average to give me the correct results. I first created a daily average to group together a series of dates. I've named this Booking Average and the results that I am getting are correct. The problem is that now I need another average which looks at Booking Average and gives me another average of the last 4 weeks. I created a unique number to group the data but when I try to create the new average it gives me the same average again as the Booking Average. The measure is called CAY average and below is the code I'm using.
=if(countrows(VALUES('Range'[Number])) = 1,
CALCULATE(
AVERAGEX(VALUES('Range'[Number]) ,
'Range'[Booking Average])
,'Range'[Number]<= VALUES('Range'[Number])
&& 'Range'[Number] > VALUES ('Range'[Number])-4)
,BLANK())
Is there a way to attach the file so someone can look at it?
Thanks

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

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.

Tableau CPC calculation

I have a problem with calculating CPC in Tableau.
I have the cost and the number of the click but Tableau is not calculating the right CPC. the formula I used : [Cost]/[Click]
I attached two tables in this request. first shows the table which I calculated all KPIs in Zeppelin. the second the calculation in Tableau.
The whole data set has many null and 0 values, but it is the same data set used in zeppelin.
May I ask for help,how to solve this issue?
The result of CPC is not correct in Tableau.
Helena,
the issue is that Tableau is using aggregate functions when you add measures, and in this case of CPC calculation, it's not correct.
Tableau is doing [cost]/[click] division (on row-level) and then simply averages all those numbers (you are basically calculating an average of an already average number).
What you are after is a bit different and you have to fix the math to make sure all costs are aggregated first and then divided by sum of all clicks, so:
SUM([cost]) / SUM([clicks])
This will give you the correct and mathematically sound numbers.
Hope this helps.
SUM([cost]) / SUM([clicks]) will resolve the issue