Summing average aggregation in grand total (DAX) - excel

I created a measure in PowerPivot that has the following formula:
Calculated Percentage:=[PercentageA]+[PercentageB]*AVERAGE([Multiplier])
Here is the result:
What I would like from this measure is in the Desired values column. The point would be to see the grand total as the SUM of the values of the measure instead of multiplying the grand total PercentageB with the grand total average of Multiplier.

One way to solve this would be to use SUMX function. Which based on a provided table or column does an iterative calculation based on a formula provided, and then sums the result.
So in the below example, the VALUES( table_Name[Row Labels]) is used to create a table of unique values from the Row Lables column what it will iterate on. Then within each row grouping it will apply the defined formula.
Measure:= SUMX( VALUES( table_Name[Row Labels]),
Calculate([PercentageA]+[PercentageB]*AVERAGE([Multiplier])))
Note: Depending on how your average([Multiplier]) is defined, you may need to use calculate to override the context. E.g. if it is suppose to be the average over the entire set instead of the row.

Related

Excel - average of range doing vlookup of that range inside the formula

I have 2 tables: Ratings List- A1:A8; Rating Lookup- C1:D6.
I would like to calculate the average rating of the Ratings table based on the value of the rating in the Rating Lookup table.
I could do this creating an extra column in the Ratings table doing a lookup of the Rating Lookup table, but I'd like to know if there was a way to automatically calculate the average without adding any extra column.
Give this a try in G2:
=SUMPRODUCT((C2:C6=TRANSPOSE(A2:A8))*(D2:D6))/8
If one has Excel O365:
=SUM(VLOOKUP(A2:A8,C2:D6,2,0))/8
MATCH will return an array if lookup_value is an array. So you can try:
=AVERAGE(INDEX(Ratings_Lookup,MATCH(Ratings_List,Ratings_Lookup[Level],0),2))
Here is an example of MATCH returning an array in a version of Excel with dynamic arrays. This is in O365:

How to find the conditional minimum of a filtered column?

I would like to find the conditional minimum from a column of data, but have it respond to data filtering.
I have a sheet in excel with a summary section at the top, some graphs plotting various aspects of the data, and the data further down.
The data can be filtered, which updates the graphs, but it does not update the summary section.
The summary section show things like min, max, average, and stdev.
How do I make these respond to data filtering while also being conditional?
Essentially: find the minimum value in column A when column B is equal to X and update the result if any of the columns are filter.
I've looked at SUBTOTAL, but it does not allow conditions.
There is also functions such as SUMPRODUCT((SUBTOTAL(3,OFFSET(INDEX($A$1:$A$10,1,1),ROW($A$1:$A$10)-ROW(INDEX($A$1:$A$10,1,1)),0))=1),($B$1:$B$10="value"),$C$1:$C$10) which calculate the sum of column C, when column B equals "value" and updates when the filter is updated (given that the filter includes columns A, B and C).
If you can add one helper column that would be very helpfull for you, e.g.:
Formula used in D2:
=SUBTOTAL(3,A2)
This formula will end up leaving a 1 for visible cells, a 0 for invisible ones. You could choose to hide this column. We can test against this column in a multi-criteria array formula.
Formula in F1:
=MIN(IF((B2:B7="Z")*(D2:D7=1),C2:C7))
Confirmed through CtrlShiftEnter
Please refer to this example.
You can do the same type of formula's for your other needs (MAX, AVERAGE)

Excel formula to calculate the sum of the first n% visible rows in a filtered column

As I stated in the title, I want to calculate the sum of the first n% rows in a filtered column. The total numbers of rows in the column varies due to the filtering options, so my formula must work with different values of n.
For example :
In column A, I have 10 rows that contain values from 10 to 1 ( I sorted them from largest to smallest ).
In column B, I have 10 corresponding rows that contain 2 names: 4 of them contain the value "Tom", six of them contain the value "Jerry". When I filter the whole table and select only the rows that contain the value "Jerry", I want to be able to calculate the sum of the first 20% of the corresponding 6 number values.
This could work without any filtering if you want.
With criteria for column B in E1 and percentage you looking for in F1 with the assumption we want to round up the percentage to integers.
So formula in D1:
=SUMPRODUCT(LARGE((B2:B11=E1)*(A2:A11),ROW(A1:INDEX($A:$A,ROUNDUP(COUNTIF(B2:B11,E1)*F1,0)))))
So, without your data, I came up with this, edit to suit your situation...
So, based on the comment, I did a second version:
The helper column in col C is used with sumproduct to give the result...
You can use the percentile function in AGGREGATE with SUMIFS to do what you want:
=SUMIFS(A:A,B:B,"Jerry",A:A,">="&AGGREGATE(16,7,A1:A10/(B1:B10="Jerry"),0.8))
If you want to use the filter to do the decision:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(A1,ROW(A2:A10)-1,,1))*(A2:A10>=AGGREGATE(16,7,A2:A10,0.8)),A2:A10)

Calculate average based on different criteria in excel vba

I am new to excel vba. I have a huge set of data for which I have to calculate averages corresponding to each id. Upon search, I came to know that it can be easily done by using excel AverageIf. But I have to calculate average of numbers which are below Threshold for an id.
Below is the screenshot of sample data. For example, when I calculate the average of Price for id 1, I will only consider Price values which are below 70 for average calculation as 70 is Threshold and any value above 70 cannot be included in calculation and same goes for all other ids. I would appreciate any ideas in this regard.
AVERAGEIFS should do the job:
=AVERAGEIFS(B2:B15,A2:A15,1,B2:B15,"<="&C2)
I like the countifs but here is another way using a helper column to determine if to include in average calculation. Assumes data set up as above without repeating Threshold value against each id.
1) Convert your data to a table with Ctrl+T (with a cell in the range selected).
2) In top right cell under header Average put
=IF(B2<INDEX($C$2:$C$13,MATCH(A2,$A$2:$A$13,0)),1,"")
It will autofill down all the rows in that column.
Tailor the ranges to your actual ranges. These ranges match the image below.
3) Select a cell in the table and press Alt + N + V to generate a pivottable and place it by the side of the current table with a 2 column gap.
4) Add id to the rows and price to the Values field. The add Average to the page field and filter on 1. Then right click on price in the Values area and select Summarize value field by Average.
5) You can add more rows to the table and the formula will autocomplete so you only need to refresh the pivot to get new averages.
Note:
You could also have used a lookup table to retrieve the thresholds.

Average of sum of column values

I have a table with 2 columns : dates (1st of the month) and values. Each date can appear an unknown number of time. I am trying to find a formula that would make a yearly average of the sum of the value for each month.
I can easily make several sumproducts to have the sum of values for each month and then average but I would prefer to limit the size of the formula.
Does anyone has an idea on how to do that, or if that's even possible?
I assume that dates are in A column and values in B column.
The easiest way would be:
1) In third column (C), store the integers indicating the month. You will get this result by simple =MONTH() Excel function, ex.: =MONTH(A1), etc.
2) To get the average from particular month, say September (9th month), you need to enter the formula:
= SUMIF(C:C,"=9",B:B)/COUNTIF(C:C,"=9")
If you want the average for different month, you just change the 9 in SUMIF and COUNTIF.
You could make a pivot table, then drag the date in row field and values in value field. Then change the field setting of the values to 'average'.

Resources