Formula Accuracy

Bedford

Active Member
Joined
Feb 3, 2015
Messages
333
Office Version
  1. 365
Platform
  1. MacOS
With this formula; =LET(s,SEQUENCE(6),IF(J$7="Yes",IF(D18>9000,"over",XLOOKUP(D18,1730*(s-1),s,,-1)),0)), when D18 is set to 6920 which is an equal measure of 1730 and should result in the number 4, however it's resulting in the number 5? If I modify up to 1731 it results with the number 4 until D18 is set to 6924 then resulting in 5 which doesn't help with having it calculate accurately. The formula I'm hoping should return 4 when D18 is 6920, return 5 when D18 is 6921.
Help please.
Thank you.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Bedford,

I broke down the formula a little at a time.

In this line I converted SEQUENCE(6) into it's new array and replaced the variable "s" with that array
=LET(s,{1;2;3;4;5;6},IF(J$7="Yes",IF(D18>9000,"over",XLOOKUP(D18,1730*({1;2;3;4;5;6}-1),{1;2;3;4;5;6},,-1)),0))

In this line I calculated the result of 1730*(s-1)
=LET(s,{1;2;3;4;5;6},IF(J$7="Yes",IF(D18>9000,"over",XLOOKUP(D18,{0;1730;3460;5190;6920;8650},{1;2;3;4;5;6},,-1)),0))

The result of the XLookup should be 5 because D18 = 6920. If you want the result to be 4, you're going to need to use this formula:
=LET(s,SEQUENCE(6),IF(J$7="Yes",IF(D18>9000,"over",XLOOKUP(D18,1730*(s-1),s-1,,-1)),0))

or change the Sequence portion so that it is like this: SEQUENCE(5,,0) and not subtract one from each the sequence array.
 
Upvote 0
Bedford,

I broke down the formula a little at a time.

In this line I converted SEQUENCE(6) into it's new array and replaced the variable "s" with that array
=LET(s,{1;2;3;4;5;6},IF(J$7="Yes",IF(D18>9000,"over",XLOOKUP(D18,1730*({1;2;3;4;5;6}-1),{1;2;3;4;5;6},,-1)),0))

In this line I calculated the result of 1730*(s-1)
=LET(s,{1;2;3;4;5;6},IF(J$7="Yes",IF(D18>9000,"over",XLOOKUP(D18,{0;1730;3460;5190;6920;8650},{1;2;3;4;5;6},,-1)),0))

The result of the XLookup should be 5 because D18 = 6920. If you want the result to be 4, you're going to need to use this formula:
=LET(s,SEQUENCE(6),IF(J$7="Yes",IF(D18>9000,"over",XLOOKUP(D18,1730*(s-1),s-1,,-1)),0))

or change the Sequence portion so that it is like this: SEQUENCE(5,,0) and not subtract one from each the sequence array.
Hi Jeffrey, thank you for responding. So I've entered all 3 of your suggestions, one by one, with 6920 in D18. #1&#2 returned 5, but it should be 4<=6920, #3 returned 4 correctly, but when D18 was dropped down to 6919 it returned 3, but also should have been 4<=6920. I also tried changing the sequence to; SEQUENCE(5,,0) but it too returned 3 at 6919. Very confusing.
Thank you.
 
Upvote 0
Please try this
=LET(s,SEQUENCE(1,10,0)*1730,IF(J$7="Yes",IF(D18>9000,"over",XLOOKUP(D18,s,SEQUENCE(1,10,0),-999,-1)),0))
 
Upvote 0
Please try this
=LET(s,SEQUENCE(1,10,0)*1730,IF(J$7="Yes",IF(D18>9000,"over",XLOOKUP(D18,s,SEQUENCE(1,10,0),-999,-1)),0))
So for some reason it still returns 3 when <6920, for example 6919, but it is now returning 4 when <=6920.
 
Upvote 0
So this controls how you're going to return your numbers:
XLOOKUP(D18,s,SEQUENCE(1,10,0),-999, -1 ) returns the next lower
XLOOKUP(D18,s,SEQUENCE(1,10,0),-999, 1 ) returns the next highest
XLOOKUP(D18,s,SEQUENCE(1,10,0),-999, 0 ) returns the exact match

Play with that a little
 
Upvote 0
So this controls how you're going to return your numbers:
XLOOKUP(D18,s,SEQUENCE(1,10,0),-999, -1 ) returns the next lower
XLOOKUP(D18,s,SEQUENCE(1,10,0),-999, 1 ) returns the next highest
XLOOKUP(D18,s,SEQUENCE(1,10,0),-999, 0 ) returns the exact match

Play with that a little
I played around with the 3 options, the first two as you mention return as stated, the third option with the zero, returns a -999, that had me confused. So in using the excel formula builder which I don't have a lot of experience with, I came up with a multiple cell scenario that seems to work so I'll work with what I have here.
Thank you for taking interest.
Doug.
 
Upvote 0
Between the suggestions from my last post and the Sequence part of the formula I know you'll make it work. The Sequence function can start at zero or any other number
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,212
Members
453,023
Latest member
alabaz

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