Formula in excel that does average to all cells that matches the number in a row, the former number and next number - excel

I need to do a formula in excel that does average to column of votes if it matches to the season in that row, former, and next season (except from the first and last season). For example, if I am in a row on season 3, I need to do average of all the votes in seasons 2,3 and 4.
Right now I tried :
=AVERAGEIFS(I$2:I$237,B$2:B$237,$B2,B$2:B$237,IF($B2=1,$B2,$B2+1),B$2:B$237,IF($B2=10,$B2,$B2-1))
(I- is the column of votes, B - is the column of seasons)
But it returns error: #div/0!
This is a small example of the table.
I would like for help to solve this problem.

In Averageifs, the different conditions have an AND relationship - so at the moment you are asking for rows that match both previous season AND next season which is impossible. There aren't any, so you get the #DIV/0 error.
Try it with a range instead:
=AVERAGEIFS(I$2:I$10,B$2:B$10,">="&B2-1,B$2:B$10,"<="&B2+1)

Related

To count the unique number of values based on criteria

Column A is the list of projects and column B is the markets. Both the columns have duplicate values.
In the below example I want to count the number of unique projects in the Hong Kong market. The answer should be 8. I need the formula to calculate the same
I don't have Office 365 so the unique function will not work and I cannot use pivot. Have to use a formula.
This is the sample data the actual list consists of multiple markets and projects of sample size 200. Excel version 2016.
=SUM(--(FREQUENCY(IF(ISNUMBER(SEARCH("Hong Kong",B2:B13)),MATCH(A2:A13,A2:A13,0)),ROW(A2:A13)-ROW(A2)+1)>0))
IF checks wether Hong Kong is part of the market in the ISNUMBER, SEARCH section. And returns TRUE (1) or FALSE (0).
The MATCH part returns the row numbers of the first match of each value it searches in column A. If a value is used more than once the match will return the row number of the first match for each value.
The ROW(range)-ROW(first_value_in_range)+1 returns a sequence of the count of rows in your range.
FREQUENCY checks the occurance of the row numbers from the match-function versus the sequence created from the rows-part. If it occurs more than once FREQUENCY returns the total count of occurrences for the first and returns 0 for any next occurrence.
Finally it's summer by each frequency >0.
As this is an array formula you need to confirm the formula with ctrl+shift+enter

Only show the sum of a column if there are at least 3 records in another column

I have 3 Columns of data. Column E = Duration. The user will enter a number of days (Duration) for 20 employees. Column F = Pay. List of wage for each employee. Column R = Pay Total. This is a calculated field based on the number of days (Duration) and the employees pay (Pay).
To keep my employees from finding out their coworkers pay I only want to see a sum for Column C if there are at least 3 records in Column A.
I found this Sum only if 3
From that answer I tried to use =IF(COUNTIF(E2:E15,">2"),SUM(R2:R15))
What this does is only returns records with a duration of greater than 2 days. I don't care about the number of days. I want the indicator to be that there are 3 cells populated in this column.
I think the only issue with the formula is the CountIF part. I need to know what I should use to count cells not days.
Screenshot of My Sheet
In the image above you can see that it's returning a sum bc both records are greater than 2. Like I said before I don't care what number is in the cell I just want to see the sum if there are more than 2 cells populated in that column.
Thanks for any help
As per my understanding of the question, I came up with this solution. Give it a try.
=IF(COUNT($E$2:$E$15)>2,SUM($R$2:$R$15), 0)
This formula would give what you want
=IF(COUNTA(E2:E15)>2,SUM(R2:R15),"")
This would show sum only if count of non empty cells is greater than 2 in Range "E2:E15" else it would show empty.

Formula for average entries per day

I have a very simple sheet with dates in column A and product names in column B. I just need to know how many sales I make on average per day.
Sales:
01/01/2018 PRODUCT A
01/01/2018 PRODUCT A
01/02/2018 PRODUCT A
01/02/2018 PRODUCT B
Average sales per day: 2
So I don't care what product it is. Just how many sales per day on average.
You can use counta(a2:a5) to get the count of items in a range (adjust your range to suit of course).
You can use the array formula sum(1/countif(a2:a5,a2:a5)) to get the count of unique items in a range. The way to get an array formula is to enter it with CTRLSHIFTENTER rather than just ENTER (it will show up in the formula bar with {braces}).
It should then be a simple matter of dividing the former by the latter to get the average items per unique item (sales per day and, again, this should be an array formula):
=counta(a2:a5)/sum(1/countif(a2:a5,a2:a5))
The only tricky bit there is the countif formula. The expression countif(range,value) will give you a count of all items in the range that match the value.
By making the value the same as the range, it counts (for each item in the range) the number of times an item appears.
So, if your range contains a,a,a,a,b,b,c, you'll get the array (4,4,4,4,2,2,1). Doing the sum of the reciprocals of those values for each cell in the range gives:
(1/4 + 1/4 + 1/4 + 1/4) + (1/2 + 1/2) + (1/1)
which is basically a sneaky way of counting the unique items.
Assuming dates are entered as real Date (and not just text that only looks like dates), use this
=COUNT(A:A)/SUM(--(FREQUENCY(A:A,A:A)>0))
(Frequency formula sourced from here )

Need help in excel formula

1) I have two tables. 1st table contains data for more then 20,000 rows and 2nd table I already have the following columns details i.e. Region, Item, Number and I just have to get the Total value of the product from the 1st table
2) There are two types of prices in the 1st table . One is Retail Price and Another one is a Wholesale price
3) In each of the regions Rep, Item and Numbers are same in most of the cases, but the Total price is different
4) I am able to get the Total price details in 2nd table through vlookup formula (After concatinating the following columns i.e. Region, Item and Number from both the tables) wherever there is an account number for retail price
5) Currently I am manually updating "Total Price" details in 2nd table for Wholesale price which is taking lot of time.
Is it possible to build a formula to get the wholesale price details in the 2nd table, since there are more then one account number, but the price is same
If the wholesale price is the lowest price for the specific item, then you can find it with the formulas MIN and IF.
Based on your screen shot:
D is the column with the list of items
I5 is the cell with the item name for which you want to find the wholesale price
F is the column with the list of prices
If you enter the following formula in cell K5, it should find the lowest price for pencils
=MIN(IF(D:D=I5,F:F))
On this link, there is an explanation if you want to use multiple criteria.
http://www.contextures.com/excelminmaxfunction.html
try the sumifs function.
It takes multiple arguments and criteria. So it should look something like:
cell value at j5 = sumifs(f3:f23, b3:b23, h5, d3:d23, i5....)
you need to mark off which rows in your first table are wholesale selling. So it should be a column of some kind. Once you do that, let's say in column G, then you add onto the sumifs function...
, g3:g23, L5)
What you're doing is summing up all of the values in column F where h5 (region) matches in b3:b23, i5 (item) match in d3:d23, and where L5 (retail type) match in a new column g2:g23.
This will find all of the values that match that criteria exactly.
Vlookup is useful, but it's harder to scale IMO than the advanced if functions.
SUMIFS is probably the better way to go on this one, but as an alternative there is also SUMPRODUCT.
=SUMPRODUCT(($H3=$B$3:$B$20004)*($I3=$D$3:$D$20004)*($J3=$E$3:$E$20004)*($F$3:$F$20004))
The * acts as an AND statement in a logical check, and each of the ($H3=$B$3:$B$20004) is a logical check. When the row is true it will evaluate to 1. When it is false it will evaluate to 0. in the end you wind up with a list of prices or 0s that get summed. The end result is the sum of everything that matches your criteria.
The danger of using this formula is that it can get labour intensive as it is performing array calculations without being an array formula.

How do I check for duplicate rows and do calculate on that rows in excel file?

I have one excel file which is having data like following
CUSIP Quantity Date Price
AF0 500000 5/6/2013 1
AE4 400000 5/6/2013 1.0825
AE4 500 5/6/2013 1
I need to check for column CUSIP and Date
If I'm having duplicate CUSIP for same date then I need to do following calculation.
1.Need to add Quantity for both of them instead of showing duplicate records need to show only one record( sum of Quantity).
2.Need to do calculation on Price as well like following
NewPrice = ((400000 * 1.0825) + (500 * 1.00))/(400000 + 500) = 1.08148
For example in using above data
Need to show output like
CUSIP Quantity Date Price
AF0 500000 5/6/2013 1
AE4 400500 5/6/2013 1.082397004
How do I achieve this in excel file using LOOKUP or else ?
Okay, after quite some research (interesting question by the way!), I came up with this:
=IF(COUNTIF($A$2:A2,A2)>1,"",SUMIF(A:A,A2,B:B))
=IF(COUNTIF($A$2:A2,A2)>1,"",SUMPRODUCT(--(A:A=A2),B:B,D:D)/SUMIF(A:A,A2,B:B))
Put these in cell D2 and E2 respectively (which is the next column after Price and in the row of CUSIP AF0).
And fill to the bottom of the worksheet to get the weighted average price or each CUSIP.
The first formula gives you the total quantity for the CUSIP and the second gives you the average price.
Copy and paste values for those two columns after calculation.
Put a filter and remove all the rows where the total quantity and average price is blank, and sort to make the worksheet neat.
Let me know if this works for you! I tried it on your sample data and it seems to be working. It's my first time using SUMPRODUCT ^^;
SUMPRODUCT(--(A:A=A2)
This bit returns the rows from column A where it equals to the row's CUSIP.
SUMPRODUCT(--(A:A=A2),B:B,D:D
This additional bit tells excel to multiply the values in column B and D of each returned row found above and SUMPRODUCT adds each result together.
EDIT:
I actually forgot about the date. You could maybe add a helper column where you'll generate an identifier to separate the different dates. To make it, you'll have to make a concatenate.
Hence in cell F2, you put:
=CONCATENATE(A2,C2)
In the formulae for cells D2 and E2, you will have to change them so they become:
=IF(COUNTIF($F$2:F2,F2)>1,"",SUMIF(A:A,A2,B:B))
=IF(COUNTIF($F$2:F2,F2)>1,"",SUMPRODUCT(--(A:A=A2),B:B,D:D)/SUMIF(A:A,A2,B:B))
reEDIT: Oops, put the wrong reference. Fixed now.

Resources