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.
Related
I am trying to create a calculation table for prices based on QTY and price break tier. I have an IF formula that doesn't seem to be working correctly and could use some help! Below I will post a screenshot of the table, the formula I am using, and amplifying details:
Price Break formula: =IF(H3<=24,C3,IF(25<=H3<=99,D3,IF(100<=H3<=499,E3,IF(500<=H3<=999,F3,IF(1000<=H3,G3)))))*H3
Amplifying Info: Column "H" is derived from a sum of "J:P". What I want to do is automatically calculate the total quantity requested (Column "H") and based off of that value calculate the total price of each item in Column "I". IE if the total QTY=1 the price would be 1xC (Associated cell C3:C14); If the QTY=600, then it would be 600xF. Currently the formula only works if I manually input "1" as the QTY and no other numbers work. Column "H" is set as number (though general did the same thing). If i place any other number or what the calculation comes out to it puts a dash as shown in the picture.
I'm not sure if there is better way to do this with VLOOKUP or another function?
Try using MATCH and CHOOSE:
=CHOOSE(MATCH(H2,{0,25,100,500,1000}),C2,D2,E2,F2,G2)*H2
The MATCH will compare the qty (in H2) to the values in the array ({0,25,100,500,1000}) and return a number (1 to 5).
The CHOOSE will then take this number and choose the nth value from the list of cells (C2,D2,E2,F2,G2)
We then multiply the value in the chosen cell by the quantity in H2
I am trying to write a formula that will count unique values (both text and numbers) in a range that also has blank fields with a set of criteria.
Criteria:
Shipment Type = Specific Transport Type
Status Column = "Unplanned"
Despatch Month = Specific Month
This is very easy to execute with a pivot table. However I want to be able to write a formula instead, as I don't like the idea of having to refresh a pivot table every time new data is added.
Here is the formula I have written for Unplanned Shipping by Cost for Truck 2018-03 in cell I15:
=SUMIFS($F:$F,$C:$C,I$14,$A:$A,$H15,$B:$B,"Unplanned")
The same logic doesn't really apply when writing a =COUNTIFS formula to measure unique consignments as the unique values with blanks fields adds a layer of complexity.
to count the number of record where D:D is not blank:
write in cell I7 =countIFS($D:$D,"<>"&"",$C:$C,I$6,$A:$A,$H7,$B:$B,"Unplanned")
I am using an excel spreadsheet to keep track of some data.
I calculate median and quartile values for each column at the bottom of those columns (rows 15, 16, 17). However, I want to be able to keep adding new values into columns without changing the range of my median/quartile formula. I know I can select the whole column in my formula if I had the formula in a different cell than the column I am making calculations on.
I am wondering if there is a way to exclude the rows with my median and quartile formulas from my calculations. As I enter more data, those locations will also increase and I couldn't figure it out.
So if we know the number of blank lines to be two, before we do the median, then =median(INDIRECT(CONCATENATE("B2:B",text(row()-3,"#"))))
works, by constructing the range of column B fed to the median function to be B2 through B + whatever number is 3 up from the row where the formula sits. For the IQR presumably 3 must be increased.
I have a table which has a column with some numbers and cell containing the total value of those values in the last row which I have inserted with the AutoSum feature. I want to calculate the percentage of the number in one row of the total value. I'm doing this naively by clicking on a cell for the percentage and type = and then I click on the cell with the actual value, followed by typing / and finally clicking on the cell with the total value. What excel inserts as formula is:
=[#[Columnname]]/Table1[[#Totals];[Columnname]]
But when I hit enter excel tells that this is not a listed value.
How can I correctly address the last row's cell of this column? Note that even calling the cell with its current cell number (e.g. C8) results in the same message.
Ok the problem was, that I am using the "track tasks" template (don't know the name in english). It basically consists of a table that has a column with percentages. In the template those percentages are selected by the user from a drop down list. My modification should instead calculate those percentages. As the calculated values are not necessarily one of the drop down list values (5 in this case. 0, 25, 50, 75 and 100) and this is what excel means by "not a listed value".
I have an excel workbook with paired data sets of the type [columnA=distance:columnB=data] There are thousands of data points.
What I'm looking to do is this: I have a sectioning for column A . I want to find the average of corresponding cells in the data column (column B) for the sectioning.
You have a couple of simple options:
autofilter
filter on column A, then highlight column B and have a look at average value in the bottom right corner in the excel status bar
or create a formula =SUBTOTAL(1, B:B) somewhere in your sheet which ignores hidden cells and works well with autofilter
excel table
same as autofilter, but it comes with built-in TOTAL row feature that you can set up to display the average
=AVERAGEIFS() or similar formula - see e.g.:
Average of a filter of multiple columns in Excel,
Calculating average of specific values