News:

  • July 07, 2026, 04:33:11 AM

Login with username, password and session length

Author Topic: Excel VLOOKUP using Do-More  (Read 12965 times)

Dean

  • Sr. Member
  • ****
  • Posts: 73
Excel VLOOKUP using Do-More
« on: March 02, 2016, 03:51:46 PM »
Where I work we manufacture Purified Water. We adhere to USP PW limits for quality. One parameter is conductivity. The limit is temperature dependent. In other words, the conductivity limit changes according to water temperature, as defined by the attached image USPLimit. For instance if the water temperature is greater than or equal to 15C, and less than 20C, the conductivity limit is 1.0 micro-Siemens/cm. if the temperature is greater than or equal to 20C and less than 25C the limit is 1.1 micro-Siemens/cm, and so on. I use Excel to analyze batches of data, and look at each data pair of temperature, and conductivity, to see if the pair meets the established limit. The easiest way to do this in Excel is to use the VLOOKUP function. Most of you probably know how it works already, but if not, basically you compare a value to column 1, (Temp), and return the value in column 2 (Cond) that shares the row of column 1 that matches your value. You can then insert your VLOOKUP function into other formulas to do whatever you want. So anyway, I wanted to try to recreate a VLOOKUP in a Do-More, so I did. See attached VLOOKUP.zip. I used indirect addressing thinking I might be able to simplify pointing to the columns, but couldn't really figure that out. Didn't really need the extra step, but I left it that way. I'm sure that there is a better way to do this. Anyway, if anybody has the time, I would appreciate any feedback.
« Last Edit: March 02, 2016, 03:59:32 PM by Dean »
10 Lather
20 Rinse
30 GOTO 10

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6164
  • Yes Pinky, Do-more will control the world!
Re: Excel VLOOKUP using Do-More
« Reply #1 on: March 02, 2016, 04:41:25 PM »
Doesn't answer the VLOOKUP question, but this seems like a great application for the LERP instruction.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3619
  • Darth Ladder
Re: Excel VLOOKUP using Do-More
« Reply #2 on: March 02, 2016, 05:36:29 PM »
You can now do math in indices in MATH boxes, so:

1) R[t/5 + table_base] or create a table dedicated to the values to eliminate the base address, or
2) R[t] (+ base address, if used), and just fill in values for each degree, even if the values for consecutive temps are sometimes the same, or
3) COUNTIFLE(t) finds the row index, so long as the values are in order, so R[COUNTIFLE(t)] gives the limit, or
4) if you're allowed to interpolate, derive the equation between temp and allowed conductivity.
« Last Edit: March 02, 2016, 05:38:59 PM by Controls Guy »
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3619
  • Darth Ladder
Re: Excel VLOOKUP using Do-More
« Reply #3 on: March 02, 2016, 05:57:44 PM »
Looks like the first four are linear and the last one is an exception, so just do linear and add the extra 0.1 based on an IF().

If you don't want to do that, use

Cmax = 6.58 x 10-6 t4 - 3.28 x 10-4 t3 + 5.73 x 10-3 t2 - 2.08 x 10-2 t + 0.797
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3833
    • Host Engineering
Re: Excel VLOOKUP using Do-More
« Reply #4 on: March 02, 2016, 06:16:19 PM »
LERP is the continuous version of Excel's quantized VLOOKUP.

If you want less accuracy, we could implement VLOOKUP  ;D.

If you need help mapping your VLOOKUP table to a LERP table, we can definitely discuss it here.  For example, should the MIDPOINT of the VLOOKUP INPUT RANGE match map to the OUTPUT of the VLOOKUP, or should the START, or ?

Dean

  • Sr. Member
  • ****
  • Posts: 73
Re: Excel VLOOKUP using Do-More
« Reply #5 on: March 02, 2016, 07:08:50 PM »
I will look at the LERP instruction, but in this case, interpolation is not allowed. For example the limit @ 20, 21,22,23,and 24 Celsius is 1.1. Once the temp goes to 25, then you get 1.3. The rules are strict. If your temp is 24.99999.... the limit is 1.1, but it's also 1.1 at 20.00000001. This is new a few years ago, there was a lot of confusion surrounding conductivity testing of PW generation systems, different methods, different types of sensors, some analyzers/meters used a temperature compensated algorithm, some didn't, some companies used grab samples, some used inline sensors, and nobody was really sure if an auditor was going to accept your measurement method, and pass/fail test or not. The USP did a huge study and created a standard that was consistent, easy to understand, and implement. That's probably more than anybody cares to know about conductivity of Purified Water. Lord knows I've spent wayy too much time thinking about it.
10 Lather
20 Rinse
30 GOTO 10

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3833
    • Host Engineering
Re: Excel VLOOKUP using Do-More
« Reply #6 on: March 02, 2016, 07:34:46 PM »
For example the limit @ 20, 21,22,23,and 24 Celsius is 1.1. Once the temp goes to 25, then you get 1.3. The rules are strict. If your temp is 24.99999.... the limit is 1.1, but it's also 1.1 at 20.00000001.

Understood.  The table is small enough that you can do it in straight ladder logic (vs. doing it "generically" with a table with variable length, that contained variable limits and variable outputs)

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3619
  • Darth Ladder
Re: Excel VLOOKUP using Do-More
« Reply #7 on: March 03, 2016, 12:35:56 PM »
Don't know LERP, so for all I know that's the better method, but I can't speak to that, so I'll just tell you what I'd do.

You can use the properties of integer math to get the steps.

If your temperature is in V100 and your Cmax values are in R1000-R1004, then

Code: [Select]
Cmax = R[(V100 / 5) + 999]
OR just calculate it

Code: [Select]
MATH R1000 (V100 / 5) * 0.1 + 0.7 + IF(V100 = 25, 0.1, 0)
Not sure what happens if you start out in integer and then the expression goes real, so you might have to do V100/5 as a separate step and store the integer result, then do the other steps in a second box, but I don't think so.  The quantization from the integer math gets you your steps for free, and will return the same value over the range, as you've described.  You'll also may need to treat the edge conditions where temp is <5 or >25.  So annoying that they have the little hockey stick at T=25 or it would be even cleaner.

If your temp is a real, you'll need to make it an integer first to use this property of integer math.

I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6164
  • Yes Pinky, Do-more will control the world!
Re: Excel VLOOKUP using Do-More
« Reply #8 on: March 03, 2016, 02:01:16 PM »
Don't know LERP, so for all I know that's the better method...

Multi-point linear interpolation X to Y translation. Primarily intended for approximating non-linear functions.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Dean

  • Sr. Member
  • ****
  • Posts: 73
Re: Excel VLOOKUP using Do-More
« Reply #9 on: March 03, 2016, 05:04:24 PM »
Thanks Controls Guy,I'll study your suggestion.
10 Lather
20 Rinse
30 GOTO 10