CountIf with relative reference - excel

I have a column, G, with several dates in it, and another column, K, with several percentage values between 0 and 100%.
I also have an UDF, IsoWeekNumber, which returns the weeknumber for any given date.
What I want to do is have weeks 1 to 53 in N3:N55, and then have a formula in the column next to it counting how many of the entries for a given week aren't 100%. I've come up with this formula, but it seems that it gets the weeknumber for cell G3 only when doing the comparison.
=COUNTIFS($G$3:$G$649;IsoWeekNumber(G3)&"="&$N$3;$K$3:$K$649;"<>"&1)
So, is there any way to make the function inside the countif apply to each of the cells I am comparing? Is there a better alternative approach?
Addendum: UDF code from OP's comments -
Public Function IsoWeekNumber(InDate As Date) As Long
IsoWeekNumber = DatePart("ww", InDate, vbMonday, vbFirstFourDays)
End Function

Try using SUMPRODUCT((ISOWEEKNUM($G$3:$G$649)=N3)*($K$3:$K$649<>1))

Related

How to filter out partial match in an Excel row?

I have an Excel sheet with dates in the rows. A given month should be used only once in a row. How can I filter out, if there are two dates in the same row from the same month?
For example I have the following array, and I would like to have as a result, that there is a match in this row (2012-03).
2012-03-04 2012-02-05 2012-04-06 2012-03-07 2012-10-08 2012-11-09 2012-12-10
I have tried to combine aggregate and match functions, but I cannot find out how to do it properly.
One of my codes, of course it gave an error:
=aggregate(9,6,(MATCH("*"&LEFT(A8,7)&"*","*"&LEFT(b8,7)&"*",0), MATCH("*"&LEFT(b8,7)&"*","*"&LEFT(c8,7)&"*",0)))
Ok, now I have tried another way, and I could get a solution, but with a code which is like a km long...I have first created a new dataset, cutting down the days by using: =""&LEFT(A8,7)&""
Then I have compared all the cells in a given row of my new dataset. Could someone help me how to shorten the exact( ) parts? The aim is to compare all.
=if((or(exact(A2, B2), exact(A2,C2),exact(A2,D2),exact(A2,E2),exact(A2,F2),exact(A2,G2),exact(A2,H2),exact(A2,I2),exact(A2,J2),exact(A2,K2),exact(A2,L2),exact(A2,M2),exact(A2,N2),exact(A2,O2),exact(A2,P2),exact(A2,Q2),exact(A2,R2),exact(B2,C2),exact(B2,D2),exact(B2,E2),exact(B2,F2),exact(B2,G2),exact(B2,H2),exact(B2,I2),exact(B2,J2),exact(B2,K2),exact(B2,L2),exact(B2,M2),exact(B2,N2),exact(B2,O2),exact(B2,P2),exact(B2,Q2),exact(B2,R2),exact(C2,D2),exact(C2,E2),exact(C2,F2),exact(C2,G2),exact(C2,H2),exact(C2,I2),exact(C2,J2),exact(C2,K2),exact(C2,K2),exact(C2,L2),exact(C2,M2),exact(C2,N2),exact(C2,O2),exact(C2,P2),exact(C2,Q2),exact(C2,R2),exact(D2,E2),exact(D2,F2),exact(D2,G2),exact(D2,H2),exact(D2,I2),exact(D2,J2),exact(D2,K2),exact(D2,L2),exact(D2,M2),exact(D2,N2),exact(D2,O2),exact(D2,P2),exact(D2,Q2),exact(D2,R2),exact(E2,F2),exact(E2,G2),exact(E2,H2),exact(E2,I2),exact(E2,J2),exact(E2,K2),exact(E2,L2),exact(E2,M2),exact(E2,N2),exact(E2,O2),exact(E2,P2),exact(E2,Q2),exact(E2,R2),exact(F2,G2),exact(F2,H2),exact(F2,I2),exact(F2,J2),exact(F2,K2),exact(F2,L2),exact(F2,M2),exact(F2,N2),exact(F2,O2),exact(F2,P2),exact(F2,Q2),exact(F2,R2),exact(G2,H2),exact(G2,I2),exact(G2,J2),exact(G2,K2),exact(G2,L2),exact(G2,M2),exact(G2,N2),exact(G2,O2),exact(G2,P2),exact(G2,Q2),exact(G2,R2),exact(H2,I2),exact(H2,J2),exact(H2,K2),exact(H2,L2),exact(H2,M2),exact(H2,N2),exact(H2,O2),exact(H2,P2),exact(H2,Q2),exact(H2,R2),exact(I2,J2),exact(I2,K2),exact(I2,L2),exact(I2,M2),exact(I2,N2),exact(I2,O2),exact(I2,P2),exact(I2,Q2),exact(I2,R2),exact(J2,K2),exact(J2,L2),exact(J2,M2),exact(J2,N2),exact(J2,O2),exact(J2,P2),exact(J2,Q2),exact(J2,R2),exact(K2,L2),exact(K2,M2),exact(K2,N2),exact(K2,O2),exact(K2,P2),exact(K2,Q2),exact(K2,R2),exact(L2,M2),exact(L2,N2),exact(L2,O2),exact(L2,P2),exact(L2,Q2),exact(L2,R2),exact(M2,N2),exact(M2,O2),exact(M2,P2),exact(M2,Q2),exact(M2,R2),exact(N2,O2),exact(N2,P2),exact(N2,Q2),exact(N2,R2),exact(O2,P2),exact(O2,Q2),exact(O2,R2),exact(P2,Q2),exact(P2,R2),exact(Q2,R2))),"same month","ok")
Thank you in advance.
I am not sure if there is a better way, but this is how I'd tackle the problem based on my Excel knowledge:
Add data of dates above in cells A1-G1
On row below date add formulas for dates: A2=DATE(A1) ..... G2=DATE(G1)
At the end of the original row of dates add the numbers 1 thru 12:
using formula cell H1=1, I1=H1+1 ..... S1=R1+1
After the months on row 2:H2=COUNTIF($A2:$G2,H1) ..... S2=COUNTIF($A2:$G2,S1)Counting frequency for each of the 12 months
T2=MAX(H2:S2)
Then select on cell T2being more than 1.
Here it is as a Google sheet (you can download it and open in Excel if you want)
Maybe this will help. Assume that the range of dates is in $A$1:$G$1. Also assume that the entries are numerical dates; if they are instead text you can handle this by using the DATEVALUE function. Then we can get the years and months of the range with:
{=YEAR($A$1:$G$1)}
{=MONTH($A$1:$G$1))
This and all other formulas must be entered as array formulas (CrtlShiftEnter).
We next convert back to a date, but use 1 for the day, so that all dates get shifted to the first day of the month (this means that any dates from the same month are shifted to the same date):
{=DATE(YEARS,MONTHS,1)}
We can produce an NxN comparison of the shifted dates by:
{=TRANSPOSE(SHIFTED_DATES)=SHIFTED_DATES}
We can count the number of True's in this array by:
{=SUM(--(ARRAY))}
If there we no dates from the same month we'd expect this to sum to N because this method compare each date to itself as well as the other dates. The causes the N elements on the main diagonal of this array to be True. If any dates are in the same month off-diagonal elements will also be True. So to detect if there are dates from the same month we make the comparison:
{=SUM(--(ARRAY)) > N}
or more generally:
{=SUM(--(ARRAY)) > COUNT($A$1:$G$1)}
Rolling all of these up into one formula:
=IF(SUM(--(TRANSPOSE(DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1))=DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1)))>COUNT(DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1)),"same month","ok")
If your dates are in a range other than $A$1:$G$1 then make the appropriate substitutions.
Hope that helps.

SUMIF based on another worksheet name and month

I'm trying to write a formula and I can get it to work in parts, but not all together. I think I might need an array formula, with which I have no experience.
The formula should pull data from worksheet "2017". I want it to sum any numbers located in column R IF the value in column F or G of that row is "Name" AND the date in column N is in the month of January.
SUMIFS() do not like the OR when looking two different ranges so you will need to use SUMPRODUCT and limit the range to only the dataset:
=SUMPRODUCT(R1:R100,((G1:G100 = "Name")+(F1:F100="Name")>0)*(MONTH(N1:N100) = 1))
as per your comments your formula should be:
=SUMPRODUCT('2017'!R1:R100,(('2017'!G1:G100 = "Allison Jones")+('2017'!F1:F100="Allison Jones")>0)*(MONTH('2017'!N1:N100) = 1))
Avoid full column references as this is an array type formula and it will slow down the calculations.
I seriously misread the Q at my first attempt. What I ought to have suggested is:
=SUMIFS(R:R,F:F,"Name",N:N,">=42736",N:N,"<42767")+SUMIFS(R:R,G:G,"Name",N:N,">=42736",N:N,"<42767")-SUMIFS(R:R,F:F,"Name",G:G,"Name",N:N,">=42736",N:N,"<42767")
Not elegant but uses just the SUMIFS function to get to the result by adding all the cases where the "F" criterion applies to all the cases where the "G" criterion applies and subtracting the cases where both "F" and "G" criteria apply.
42736 and 42767 are the serial numbers in the 1900 date system for the start of January 2017 and the start of February 2017. The 'or equals' is to allow for the possibility that column N might include times.

Calculate a dynamic average from a table in excel

I have this table of currency rates:
I would like to create a formula that receives the begin date and end date + currency, and in return will calculate the average for every month inside the range.
For example, if the currency is GBP, begin date is 15/09/2015 and end date is 20/11/2015, I would like to calculate averages for 30/09/2015 + 31/10/2015 + 30/11/2015.
I tried to solve it with a simple Average + Vlookup + Match functions, but it wouldn't get me the range of cells but only the edges of the range. I also thought of using AverageIF function, but I'm not sure how to combine between the criterias of date and currency.
Can you think of an easy way to solve that?
I suggest using an index/match to get a reference to the beginning of the range of currencies then another one to get the end of the range and combining them like this:-
=AVERAGE(INDEX($B$2:$H$10,MATCH(D13,A$2:A$10,0),MATCH(1,(MONTH(E13)=MONTH($B$1:$H$1))*(YEAR(E13)=YEAR($B$1:$H$1)),0)):
INDEX($B$2:$H$10,MATCH(D13,A$2:A$10,0),MATCH(1,(MONTH(F13)=MONTH($B$1:$H$1))*(YEAR(F13)=YEAR($B$1:$H$1)),0))
)
Where the currency name is in D13, start date in E13 and end date in F13, and the table is in A1:H10.
Result: 1.5203
Must be entered as an array formula using CtrlShiftEnter
Found a way to solve this, by using the AVERAGEIF function. Enjoy, and thanks for helping!

Sumproduct including a workday function

I am using this formula to determine if the date is column F occurs after the date in column G, but before the date in column G + 3 work days.
I was using the following formula which worked quite well:
=SUMPRODUCT(($F$5:$F$1000>$G$5:$G$1000)*($F$5:$F$1000<($G$5:$G$1000+3)))
But I realized I was not accounting for weekends in the final "+3."
So I tried this:
=SUMPRODUCT(($F$5:$F$1000>$G$5:$G$1000)*($F$5:$F$1000<(WORKDAY($G$5:$G$1000,3))))
And it returns #VALUE! This happens whether I push Ctrl+Shift+Enter or not.
How do I make this work please?
As appointed by #Tim, the workday function cannot accept a range. But you can simulate what you need with the weekday function by using this:
If(weekday(G2:G5; x)>=y;5;3)
Where x is your code of sunday, y is Wednesday. If your working day is greater than wednesday, then you will sum 5, not 3.
=SUM(IF($F$2:$F$3 > $G$2:$G$3; 1; 0)*
IF($F$2:$F$3 < $G$5:$G$1000 + IF(WEEKDAY($G$2:$G$3)>= Y ;5;3); 1; 0))
Weekday does accept a range, and it returns a range of weekdays. When you compute if (that also accepts a range) you create an 0/1 matrix (which is like your
indicator matrix of rows where the condition is active). If you * both matrix of conditions, you will have the remaining rows that matches both conditions. And lastly, if you apply the sum, you will get the count.
This is a way to simulate sumproduct when you have conditions that requires a formula
You will have to use ctrl +shift + enter.
03/09/2015 02/09/2015
07/09/2015 03/09/2015
Using this dates i obtained the result of 2.
Which is correct, both dates are greater than their partners but lower than their partners + 3 working days
P.S: I use spanish Excel, so it can be mistakes of formula translating
Lori_m, in the comments to my question provided a working answer:
Try inserting a + sign into the formula to convert the range to an array: WORKDAY(+$G$5:$G$1000,3) – lori_m 17 hours ago
Thanks.
The Start_Date argument of the WORKDAY function cannot accept a range (eg $G$5:$G$1000 in your code). I'm not exactly sure what your trying to do without more details and some sample data, so that's the best help I can give you.

Using month qualification in SUMIFS statment

Here's what I'm looking for....
Trying to Sum the count of worksheet 'Results 2013' column G items
IF Cell A matches "Canada"
IF Cell E (date) is July
Having trouble with the date portion of the SUMIFS statement below.
SUMIFS('Results 2013'!$G$2:$G$510,'Results 2013'!$A2:$A$510
,"=Canada",'Results 2013'!$E2:$E510,MONTH('Results 2013'!$E2:$E510)=7)
Example value of "Results 2013"$E$480 is
I try this formula, and it provides back "January" which is obviously incorrect.
=TEXT(MONTH('Results 2013'!$E$480),"mmmm")
However, this formula, results in TRUE or 1
=IF(MONTH('Results 2013'!$E$480)=7,1,0)
The simplest solution is to add a column Month using the MONTH function to compute values, and then refer to this new column in SUMIFS.
This tests whether the date values in column E fall within the range 7/1/2013 and 7/31/2013. If your dates all fall within 2013, it will work.
SUMIFS('Results 2013'!$G$2:$G$510,'Results 2013'!$A2:$A$510,"=Canada",
'Results 2013'!$E2:$E510,">="&DATE(2013,7,1),
'Results 2013'!$E2:$E510,"<="&DATE(2013,7,31))
This array formula will work with the more general case of dates falling within any year:
=SUM(G2:G510*(A2:A510="Canada")*(MONTH(E2:E510)=7))
You could use an array formula , then you can use month on the entire column:
{SUM(if('Results 2013'!$A2:$A$510="Canada",1,0)*if(MONTH('Results 2013'!$E2:$E510)=7,'Results 2013'!$G$2:$G$510,0))}
just remember to use ctrl+shift+enter rather than the usual enter to finish the formula

Resources