Formula Help

Newbie73

Board Regular
Joined
Feb 4, 2024
Messages
109
Office Version
  1. 365
Platform
  1. Windows
Hello, I have the following formula:

=MAP(F2:F9904,LAMBDA(x,IF(x="R",LET(c,C2:C9904,r,ROW(c),s,ROW(x),y,(r>=s-8)*(r<s-0)+(r>s+0)*(r<=s+8),SUM(y*(c>"B0"))/SUM(y)),"")))

And this is the example spreadsheet:

Example.xlsx

Explaining the best I can, if F="R" then check the 8 rows above and below (ignoring the row itself where F="R") and if in the checked rows C is different than "B0" count it and divide it by the total number of rows checked.

This provides me the results on G which is perfect. I was wondering if this formula could be changed slighlty to instead of counting 8 rows above and below (if C different than the value "B0"), to count if C is different than the value "B0" and the date on Column D is within 7 days

So in the example spreadsheet, F2 ="R" so count all the rows that are within 7 days of D2 and that C is different than the value "B0"

I've added the wanted results on Column I

Thank you!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I think this is what you want but there are some mismatches.
Book1
CDEFGHI
1answerwanted resultcheck
2B53/20/17R0.2857140.28570FALSE
3B13/21/170TRUE
4B03/22/170TRUE
5B53/23/17R0.2000000.20000TRUE
6B03/24/170TRUE
7B03/25/170TRUE
8B03/26/170TRUE
9B03/27/170TRUE
10B03/28/170TRUE
11B03/29/170TRUE
12B03/30/170TRUE
13B03/31/170TRUE
14B04/1/170TRUE
15B04/2/170TRUE
16B04/3/170TRUE
17B02/4/17R0.0000000.00000TRUE
18B04/5/170TRUE
19B04/6/170TRUE
20B04/7/170TRUE
21B54/8/170TRUE
22B04/9/170TRUE
23B04/29/170TRUE
24B04/11/170TRUE
25B04/12/170TRUE
26B04/13/170TRUE
27B04/14/170TRUE
28B04/15/17R0.1250000.11110FALSE
29B04/16/170TRUE
30B04/17/170TRUE
Sheet1
Cell Formulas
RangeFormula
G2:G30G2=IF(F2:F30="R", IFERROR(MAP(D2:D30,LAMBDA(m,SUM((D2:D30>=m-7)*(D2:D30<=m+7)*(C2:C30<>"B0")*(m<>D2:D30))/ COUNTIFS(D2:D30,">="&m-7,D2:D30,"<="&m+7,D2:D30,"<>"&m))),0),"")
I2:I30I2=G2:G30=H2:H30
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I2:I30Cell Value=FALSEtextNO
 
Upvote 0
Thank you! The first one is just because I did only 4 digits decimal cases, last one is just a mistake on my manual maths that I just double check so that formula works!

Say that I would adapt that formula to another version, instead of within 7 days of the date would be between 8 and 14 days, how would I change it in the formula?

Thank you so much!
 
Upvote 0
I've added LET to make the references more manageable, but you would change the -7 (# days before) and +7 (# days after).
Rich (BB code):
=IF(F2:F30="R",MAP(D2:D30,LAMBDA(m,LET(c,C2:C30,d,D2:D30,k,(d>=m-7)*(d<=m+7)*(m<>d),IFERROR(SUM(k*(c<>"B0"))/SUM(k),0)))),"")
 
Upvote 0
I've added LET to make the references more manageable, but you would change the -7 (# days before) and +7 (# days after).
Rich (BB code):
=IF(F2:F30="R",MAP(D2:D30,LAMBDA(m,LET(c,C2:C30,d,D2:D30,k,(d>=m-7)*(d<=m+7)*(m<>d),IFERROR(SUM(k*(c<>"B0"))/SUM(k),0)))),"")
Amazing, thank you so much for your help!
 
Upvote 0
Hello, sorry I've opened a new thread today without realising I could still use this one! Your formula:

=IF(F2:F30="R",MAP(D2:D30,LAMBDA(m,LET(c,C2:C30,d,D2:D30,k,(d>=m-7)*(d<=m+7)*(m<>d),IFERROR(SUM(k*(c<>"B0"))/SUM(k),0)))),"")

Is working great, but it's really heavy on the spreadsheet especially as there's a few variations I need to do with the same formula. It's probably a long shot but is there perhaps a easier or more efficient way of doing it or with some change into the formula? As the loading/Calculating time after using has massively increased.

Sadly I know that excel struggles with more data and some formulas (Something like SQL would be better) but that's not an option so just thought it giving it a try and see if something could be done to it

Thanks and no worries if not!
 
Upvote 0
Is your date always in sequential order with no repeats like 1/1/24, 1/2/24, 1/3/24, etc...?
 
Upvote 0
Is your date always in sequential order with no repeats like 1/1/24, 1/2/24, 1/3/24, etc...?
It's order from oldest to younger date but doesn't have necessary every day if that matters but there can be cases where theres two or more events in the same date, so it would repeat itself 2 or 3 times next.

Test.xlsx

This is another example I had create to a thread, you can see an example for the dates on Column A. Do let me know if you need anything and if nothing can be done about no worries thank you anyway :)
 
Upvote 0
I don't see a more efficient way with the formula. For each cell in the date column, it's checking against the entire date column so say you have 100K rows, so it's checking (100K)^2 times plus other computations. Are you open to the VBA option? That might be more efficient.
 
Upvote 0

Forum statistics

Threads
1,223,881
Messages
6,175,159
Members
452,615
Latest member
bogeys2birdies

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