I am looking for a solution to following issue :
I want to know the sum of A/Cs 3, 4 and 5 all the time in H7 (In Picture).
But, I will also want to sort the date occasionally to verify the next due but without affecting H7
But, What actually happens when sorting in ascending order, the Cell index itself is getting changed and the value at H7 gives me the different value (which is not what I want).
Is it possible to freeze the Cell index during sort?
Use the formula to calculate total:
=SUMIFS(B4:B8,A4:A8,">=3",A4:A8,"<=5")
What this does is it adds the values in the range B4:B8 only when values in range A4:A8 is greater than or equal to 3 and less than or equal to 5.
Try a SUMIF function with OR criteria.
=SUM(SUMIF(A:A, {3,4,5}, B:B ))
Related
I want to get the count of cells used in an excel function.
For example say I have a sum function ='CV'!D11+Farmer!D11+'County'!D11+Rt!D11+WT!D11+'Country'!D11
I need a function that will tell me how many cells were used to get the total sum. In this case it is 6. The tricky part is if one of the cells used is blank I do not want it counted. For instance say cell D11 on the Farmer sheet is blank I do not want it counted in the total. So the total should be 5.
Use COUNT:
=COUNT('CV'!D11,Farmer!D11,'County'!D11,Rt!D11,WT!D11,'Country'!D11)
It will only count the cell if it has a number
You should really try to collate all your data in to a single sheet before running calculations. For the sake of example, I'll assume you have it in the range A1:A5, then you can add handling of the various cases using array formulas:
Get the count of non-empty cells (the ISBLANK function is untrustworthy in my experience): {SUM(IF(LEN(A1:A5)>0,1,0))}
Get the sum of those cells: SUM(A1:A5)
(must use Ctrl+Shift+Enter to enter the formula as an array formula, you will know it worked if the formula shows like {IF(...)} with the curly brackets)
Because blank/missing values are treated implicitly as 0 in the SUM function, this case is simple. If you have other validations then you'd have to write an array formula for the summation as well. For example, only including numbers between a min and max threshold (e.g. if you want to exclude outliers):
{SUM(IF(AND(A1:A5 >= yourMinValue, A1:A5 < yourMaxValue), A1:A5, 0)}.
If I understand your question correctly, you want to literately count the number of cells used in a formula which in your example is summing 6 values from 6 different locations.
I used the following example to demonstrate my solution:
The sum of =A1+B1+C1+D1+E1+F1 is 10 where cell C1 has a 0 value in it but cell E1 is blank.
Using the following array formula I was able to count the number of cells that have a value other than 0:
=SUMPRODUCT(IFERROR(ABS(N(INDIRECT(TRIM(MID(SUBSTITUTE(RIGHT(FORMULATEXT(A3),LEN(FORMULATEXT(A3))-1),"+",REPT(" ",100)),100*ROW(INDIRECT("1:"&LEN(FORMULATEXT(A3))))-99,100)))))>0,0)*1)
Please note you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar otherwise they will not function correctly.
The logic is to use a combination of TRIM+MID+SUBSTITUTE+RIGHT+FORMULATEXT+REPT+ROW+INDIRECT to extract the cell addresses from the original formula, then use INDIRECT to convert the cell address into the values stored in those cells, then use a combination of IFERROR+ABS+N to find out if any of these values are not 0, and lastly use SUMPRODUCT to add up all the TRUE results.
It is obvious that there are a couple limitations of my solution:
If your actual formula is not strictly in the form of A+B+C+D+E+F, then my SUBSTITUTE part of formula will need further modification;
The formula will treat cells containing 0 as blank and does not include them in the count.
Let me know if you have any questions. Cheers :)
Suppose the following series:
I am trying to find the latest non 1 value that precedes the latest 1.
In this case it should return 3 and not 4.
1 being the minimum value I have tried to use MATCH(MIN(range),range,0) and add 1 to get the value I needed, but the minimum function gets stuck on the first occurrence of the minimum.
Try
=INDEX(B1:P1,1,MATCH(1,(OFFSET(B1:P1,,-1)=1)*(B1:P1>1),0))
Where B1:P1 is your data range. Of course it is an array formula (SHIFT+ENTER).
Hope that helps.
I can't see a short and snappy answer to this but here is one suggestion assuming the data starts in column A
=INDEX(2:2,AGGREGATE(15,6,COLUMN(INDEX(2:2,MATCH(1,2:2,0)):INDEX(2:2,MATCH(999,2:2)))/(INDEX(2:2,MATCH(1,2:2,0)):INDEX(2:2,MATCH(999,2:2))>1),1))
If the range didn't start in column A, you would have to subtract the number of the column before the first column of the range from the column number returned by the AGGREGATE to get the correct index value relative to the start of the array e.g. for B2:Z2
=INDEX(B2:Z2,AGGREGATE(15,6,COLUMN(INDEX(B2:Z2,MATCH(1,B2:Z2,0)):INDEX(B2:Z2,MATCH(999,B2:Z2)))/(INDEX(B2:Z2,MATCH(1,B2:Z2,0)):INDEX(B2:Z2,MATCH(999,B2:Z2))>1),1)-COLUMN(A:A))
To be honest it wouldn't be worth using a MATCH to find the last number in the range unless the number of cells in the range was very large, so the formula for B2:Z2 would just be
=INDEX(B2:Z2,AGGREGATE(15,6,COLUMN(INDEX(B2:Z2,MATCH(1,B2:Z2,0)):Z2)/(INDEX(B2:Z2,MATCH(1,B2:Z2,0)):Z2>1),1)-COLUMN(A:A))
Formula starting column A
Formula starting at column B
i need a formula to distribute values across a range while accounting for the max value possible
conditions to check:
IF the cell value is less than max then take cell value, ELSE
subtract cell value from max AND
check conditions if there is a remainder in the subtraction and add to the next row; otherwise place 0
sample data & ideal outcome breakdown is the ideal outcome
i know VBA can solve this but i'd rather not if possible. thanks for any help.
Also, not against using a helper column :)
Updated
when the values are the same on the series, it replaces with a 0 any idea it can dynamically reset based on the length of the series
put this in B3 and copy down:
=IF(A3<>A2,MIN(A3,$B$1),MIN(A3-SUM(INDEX(B:B,MATCH(A3,A:A,0)):B2),$B$1))
When I calculate the median of even numbers for e.g 1,2,3,4,5,6,7,8.. i want the return value to be 5 i.e. the higher value of the two middle values and not the average of 4 & 5. Please help
I don't have Excel, so I can't try it, but I think you should be able to accomplish this with a combination of the LARGE function the COUNT function, and the TRUNC function. For example, if the numbers you are working with are in cells A1 through A8, you should be able to find the answer you want, though technically it's not the median, with the formula
=LARGE(A1:A8,TRUNC(COUNT(A1:A8)/2))
Edit
=LARGE(A1:A8,TRUNC((1+COUNT(A1:A8))/2))
If you know you will always be working with an even number of entries, the call to TRUNC could be omitted.
With data in column A:
=IF(ISODD(COUNT(A:A)),MEDIAN(A:A),ROUNDUP(MEDIAN(A:A),0))
EDIT#1:
Consider the array formula:
=IF(ISODD(COUNT(A:A)),MEDIAN(A:A),MIN(IF(A:A>MEDIAN(A:A),A:A)))
If the number of values is odd, return the median. If the number of value is even, return the smallest value greater than the median.
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
This approach does not require the data to be sorted.
EDIT#2:
This array formula appears to handle Ron's case:
=IF(ISODD(COUNT(A:A)),MEDIAN(A:A),MIN(IF(A:A>=MEDIAN(A:A),A:A)))
It returns the smallest value greater than or equal to the median (for the even case)
But I don't know if this is what the Poster wants.
=LARGE(A1:A9,INT((COUNT(A1:A9)/2)+0.5))
you can use Roundafter the Median
in your case you can type: =ROUND(MEDIAN(B4:I4),0)
lets say that the given range is from B4 to I4 from 1 to 8.
I have a simple worksheet with 2 columns
I want to get all the results(on column "H") (I can get only the first occurrence,I want to know if I can get the others) that contains the value from cell G1, is that possible without a macro ? any way of doing it would be appreciated...Any ideas?
You can use ROW() and SMALL() to get those instead of MATCH() since this always gets the first match.
=IFERROR(INDEX($C$4:$C$7,SMALL(IF($D$4:$D$7=$G$1,ROW($D$4:$D$7)-(ROW()-1)),ROWS($D$4:D4))),"Null")
So, if the array $D$4:$D$7=$G$1 returns true (i.e. the value equals that in G1), you will get the row numbers of these values, in this case, you will get 4 and 6. All the other will return False.
After some processing with -(ROW()-1), the 4 and 6 become 1 and 3. those two values are what will be fed to the INDEX.
SMALL() then picks the smallest, starting with the 1st (you get 1 from ROWS($D$4:D4)) and when you drag the formula down, the ROWS become ROWS($D$4:D5) which gives 2, and SMALL ends up taking the 2nd smallest value, which is 3.
EDIT: Forgot to mention. You have to array enter the above formula. To do this, type the combination keys of Ctrl+Shift+Enter after typing the formula (edit the formula again if necessary) instead of Enter alone.