Formula for if 2 criteria are met

Trie1977

New Member
Joined
Mar 7, 2022
Messages
22
Office Version
  1. 2019
Platform
  1. Windows
Hi there,

Played around now for some days.
Hope to find an answer here, and I would be very happy.

Count.xlsx
ABCDEFGHIJKLMNOPQR
1
2I am not able to combine A10 with A12 for exampleFormula triedShould Be
3Pips+ & OI +99why this seems to work?Query 1 : count how many times it occures that the week closed positive AND the Open Interest was higher than the previous week.
4Pips- & OI +5213and why not this?Query 2 : count how many times it occures that the week closed negative AND the Open Interest was higher than the previous week.
5Pips+ & OI loweri have no clueQuery 3 : count how many times it occures that the week closed positive AND the Open Interest was lower than the previous week.
6Pips- & OI loweri have no clueQuery 4 : count how many times it occures that the week closed negative AND the Open Interest was lower than the previous week.
7Pips- & OI lower streaki have no clueQuery 5 : count how many times it occures that the week closed negative AND the Open Interest was higher for 2 weeks in a row.
8
9Already figured out
10Pips+31Query 6 : count how many times bars closed higher
11Pips-30Query 7 : count how many times bars closed lower
12OI Higher Streaks >16Query 8 : count how many times it occures that the Open Interest was higher for 2 weeks in a row.
13OI Lower Streaks >19Query 9 : count how many times it occures that the Open Interest was lower for 2 weeks in a row.
Formulas
Cell Formulas
RangeFormula
B3B3=COUNTIFS('GBPUSD10080 Result after'!$J$5:$J$65,">1"&SUMPRODUCT(--('GBPUSD10080 Result after'!$N$5:$N$65>'GBPUSD10080 Result after'!$N$6:$N$66)))
B4B4=COUNTIFS('GBPUSD10080 Result after'!$J$5:$J$65,"<1"&SUMPRODUCT(--('GBPUSD10080 Result after'!$N$5:$N$65>'GBPUSD10080 Result after'!$N$6:$N$66)))
B10B10=COUNTIFS('GBPUSD10080 Result after'!$J$5:$J$65,">0")
B11B11=COUNTIFS('GBPUSD10080 Result after'!$J$5:$J$65,"<0")
B12B12=SUM(--(FREQUENCY( IF('GBPUSD10080 Result after'!$N$5:$N$65>'GBPUSD10080 Result after'!$N$6:$N$66, ROW('GBPUSD10080 Result after'!$N$5:$N$65)), IF('GBPUSD10080 Result after'!$N$5:$N$65<='GBPUSD10080 Result after'!$N$6:$N$65, ROW( 'GBPUSD10080 Result after'!$N$5:$N$65))) >1))
B13B13=SUM(--(FREQUENCY( IF('GBPUSD10080 Result after'!$N$5:$N$65<'GBPUSD10080 Result after'!$N$6:$N$66, ROW('GBPUSD10080 Result after'!$N$5:$N$65)), IF('GBPUSD10080 Result after'!$N$5:$N$65>='GBPUSD10080 Result after'!$N$6:$N$65, ROW( 'GBPUSD10080 Result after'!$N$5:$N$65))) >1))
Press CTRL+SHIFT+ENTER to enter array formulas.


DataSheet;

Count.xlsx
BCDEHJKLNOPQRSTUVWXYZAA
2BRITISH POUND - CHICAGO MERCANTILE EXCHANGEUSD INDEX - ICE FUTURES U.S.
3
4COT GetCOT DateStart CandleOpenCloseClosesPipsUpDownOI GBPOI USDGBP LongGBP ShortTotalGBP % LGBP % SNet Pos.USD LongUSD ShortTotalUSD % LongUSD % ShortNet Pos.
5############2022.02.27########-78128-107211869566514767948016####49,82%50,18%-337437618987####83%17%34774
6############2022.02.20########-17753-313188443549224224948058####46,78%53,22%-58094372676425136885%15%36084
7############2022.02.13########4492-64195302542835015147914####51,14%48,86%22374234969634931286%14%35386
8############2022.02.06########27111-42197948536034470953254####45,64%54,36%-8545403706605####86%14%33765
9############2022.01.30########134235-6184007564772959753202####35,75%64,25%-23605438979326####82%18%34571
10############2022.01.23########-15614-193182040523283666644429####45,21%54,79%-7763417724911####89%11%36861
11############2022.01.16########-12117-128183234532833978040007####49,87%50,15%-247423695935####88%12%36434
12############2022.01.09########103169-48#####572183050659672####33,83%66,17%-29166458727980####85%15%37892
13############2022.01.02########6269-99#####5808925980651519113128,51%71,49%-39171477508672####85%15%39078
14############2021.12.26########150158-3#####578922309373812####23,83%76,17%-507194716910380####49%11%36789
15############2021.12.19########152198-66#####561622082478510####20,96%79,04%-576864622211107####47%11%35115
16############2021.12.12########-12128-75213210520982949780245####26,88%73,12%-507484226311022####39%10%31241
17############2021.12.05########4571-57238310599944895087227####35,95%64,05%-382774305881935125132%6%34865
18############2021.11.28########-10238-138#####521725209990998####36,41%63,59%-388994201061314814129%4%35879
19############2021.11.21########-1202-174213313576945012284701####37,18%62,82%-345794711611341####35%8%35775
20############2021.11.14########36107-11#####593875044382042####38,07%61,93%-3159947959130516101036%10%34908
21############2021.11.07########-64130-124186898577135400466097####44,97%55,03%-120934652111073####39%9%35448
22############2021.10.31########-18024-251166780579475725542208####57,56%42,44%150474539510413####46%10%34982
23############2021.10.24########-4987-75156495589935191236959####58,41%41,59%1495345189107325592151%12%34457
24############2021.10.17########179-46158961607314911247497####50,84%49,16%16154756811634####49%12%35934
25############2021.10.10########131158-46172829628364679458773####44,33%55,67%-119794939414332####47%14%35062
26############2021.10.03########5898-27182338571944813768155####41,39%58,61%-200184471512689####38%11%32026
GBPUSD10080 Result after
Cell Formulas
RangeFormula
J5:J26J5=(H5-E5)/10
K5:K26K5=(F5-E5)/10
L5:L26L5=(G5-E5)/10
Y14:Y26,S5:S26S5=IF(P5="","",P5/$R5)
Z14:Z26,T5:T26T5=IF(P5="","",Q5/$R5)
Y5:Y13Y5=IF(V5="","",V5/$X5)
Z5:Z13Z5=IF(V5="","",W5/$X5)
X14:X26,R14:R26R14=P14+Q14
AA14:AA26,U14:U26U14=P14-Q14
Cells with Conditional Formatting
CellConditionCell FormatStop If True
Q5:AA13Cell Value<Q6textNO
Q5:AA13Cell Value>Q6textNO
P6:P13Cell Value<P7textNO
P6:P13Cell Value>P7textNO
P5,P14:AA64Cell Value<P6textNO
P5,P14:AA64Cell Value>P6textNO
O5:O64Cell Value<$O6textNO
O5:O64Cell Value>$O6textNO
N5:N64Cell Value<$N6textNO
N5:N64Cell Value>$N6textNO
L5:L65Cell Value<0textNO
L5:L65Cell Value>0textNO
K5:K65Cell Value<0textNO
K5:K65Cell Value>0textNO
J5:J65Cell Value<0textNO
J5:J65Cell Value>0textNO



Thank anyways for your time.
Tony.
 
Thank you so much. I will study this closer. At first glance it works perfectly fine now.

On last thing...

As time goes by, more rows will come. What is the best approach to incluse those rows?

  • Give the table a name and always refer to that table name instead of the row numbers?
  • Simply change the rows in the formula to let's say 5-100000 & 6-100001?
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You’re welcome…I’m happy to help. As time goes by, I think there are two approaches to consider. One is to highlight the formulas that need to be changed and then do a search and replace all to change the ranges. Another option, probably better, is to use the Name Manager to give short but meaningful names to each of the ranges and then revise the formulas to use the Range Names. This will shorten the formulas considerably and make them easier to understand; and any future revisions to the size of the ranges would involve making just a few changes in the Name Manager while the formulas remain unchanged. The other option you mentioned—converting the data table to a formal table and then using structured references—wouldn’t be advisable in this case because your formulas use an offset on the OI column in some places, so any reference to OI would give the entire table column rather than the offset. The Named Range approach overcomes this issue.
 
Upvote 0
To clarify my last post, here is an example where I've defined three named ranges in the Name Manager and then used Find/Replace All in the formulas to change the references to these Named Ranges. In the future, any changes in the length of the data table can be accommodated by editing these Named Ranges in the Name Manager, while the formulas will remain unchanged.
MrExcel_20220310_Trie.xlsx
ABC
2Results
3Pips+ & OI higher6Query 1: count how many times the week closed positive AND the Open Interest was higher than the previous week
4Pips- & OI higher5Query 2: count how many times the week closed negative AND the Open Interest was higher than the previous week
5Pips+ & OI lower6Query 3: count how many times the week closed positive AND the Open Interest was lower than the previous week
6Pips- & OI lower5Query 4: count how many times the week closed negative AND the Open Interest was lower than the previous week
7Pips- & OI lower streak >=22Combo Query 5A: count how many times the week closed negative AND there was a streak of at least 2 consecutive weeks where Open Interest was higher (AND applies to all elements in streak)
8Pips+ & OI higher streak >=21Combo Query 5B: count how many times the week closed positive AND there was a streak of at least 2 consecutive weeks where OI was higher (AND applies to all elements in streak)
9Pips+ & OI lower streak >=22Combo Query 5C: count how many times the week closed positive AND there was a streak of at least 2 consecutive weeks where Open Interest was lower (AND applies to all elements in streak)
10Pips- & OI lower streak >=21Combo Query 5D: count how many times the week closed negative AND there was a streak of at least 2 consecutive weeks where OI was lower (AND applies to all elements in streak)
11
12Pips+12Query 6: count how many times bars closed higher
13Pips-10Query 7: count how many times bars closed lower
14OI Higher Streaks >12Query 8: count how many streaks of at least 2 consecutive weeks occur where Open Interest was higher than the previous week
15OI Lower Streaks >14Query 9: count how many streaks of at least 2 consecutive weeks occur where Open Interest was lower than the previous week
161Query 10: count how many streaks of exactly 2 consecutive weeks occur where Open Interest was higher than the previous week
170Query 11: count how many streaks of exactly 3 consecutive weeks occur where Open Interest was higher than the previous week
181Query 12: count how many streaks of at least 3 consecutive weeks occur where Open Interest was higher than the previous week
190Query 12: count how many streaks of exactly 4 consecutive weeks occur where Open Interest was higher than the previous week
200Query 12: count how many streaks of exactly 5 consecutive weeks occur where Open Interest was higher than the previous week
211Query 12: count how many streaks of exactly 6 consecutive weeks occur where Open Interest was higher than the previous week
Formulas (2)
Cell Formulas
RangeFormula
B3B3=SUMPRODUCT(--(Close>0),--(OI>OIoffset))
B4B4=SUMPRODUCT(--(Close<0),--(OI>OIoffset))
B5B5=SUMPRODUCT(--(Close>0),--(OI<OIoffset))
B6B6=SUMPRODUCT(--(Close<0),--(OI<OIoffset))
B7B7=SUM(--(FREQUENCY(IF((Close<0)*(OI>OIoffset),ROW(OI)),IF(((Close>=0)+(OI<=OIoffset))>0,ROW(OI)))>1))
B8B8=SUM(--(FREQUENCY(IF((Close>0)*(OI>OIoffset),ROW(OI)),IF(((Close<=0)+(OI<=OIoffset))>0,ROW(OI)))>1))
B9B9=SUM(--(FREQUENCY(IF((Close>0)*(OI<OIoffset),ROW(OI)),IF(((Close<=0)+(OI>=OIoffset))>0,ROW(OI)))>1))
B10B10=SUM(--(FREQUENCY(IF((Close<0)*(OI<OIoffset),ROW(OI)),IF(((Close>=0)+(OI>=OIoffset))>0,ROW(OI)))>1))
B12B12=SUMPRODUCT(--(Close>0))
B13B13=SUMPRODUCT(--(Close<0))
B14B14=SUM(--(FREQUENCY(IF(OI>OIoffset,ROW(OI)),IF(OI<=OIoffset,ROW(OI)))>1))
B15B15=SUM(--(FREQUENCY(IF(OI<OIoffset,ROW(OI)),IF(OI>=OIoffset,ROW(OI)))>1))
B16B16=SUM(--(FREQUENCY(IF(OI>OIoffset,ROW(OI)),IF(OI<=OIoffset,ROW(OI)))=2))
B17B17=SUM(--(FREQUENCY(IF(OI>OIoffset,ROW(OI)),IF(OI<=OIoffset,ROW(OI)))=3))
B18B18=SUM(--(FREQUENCY(IF(OI>OIoffset,ROW(OI)),IF(OI<=OIoffset,ROW(OI)))>=3))
B19B19=SUM(--(FREQUENCY(IF(OI>OIoffset,ROW(OI)),IF(OI<=OIoffset,ROW(OI)))=4))
B20B20=SUM(--(FREQUENCY(IF(OI>OIoffset,ROW(OI)),IF(OI<=OIoffset,ROW(OI)))=5))
B21B21=SUM(--(FREQUENCY(IF(OI>OIoffset,ROW(OI)),IF(OI<=OIoffset,ROW(OI)))=6))
Named Ranges
NameRefers ToCells
Close='GBPUSD10080 Result after'!$J$5:$J$65B3:B10, B12:B13
OI='GBPUSD10080 Result after'!$N$5:$N$65B14:B21, B3:B10
OIoffset='GBPUSD10080 Result after'!$N$6:$N$66B14:B21, B3:B10
 
Upvote 0
Thank you. I will try this.

I want to say how happy I am with your help. So kind.

Should I close this thread now here at the board?
 
Upvote 0
I'm happy to hear that you've found this helpful. Typically, threads remain open so that you or others can respond with further inquiries about the topic or offer alternative approaches to address the issue.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top