Home Search

DriveWorks Solo 21
DWHLookup

Send Feedback

DWHLookup

Returns a value from a table corresponding to a match found in the specified row.

Syntax

DWHLookup([Value], [Table Name], [Lookup Row], [Result Row Index], [MatchType])

Where:

Value is the value to be found.

Table Name is the table within which the value is to be found.

Lookup Row is the number of the row containing the data to be searched for.

Result Row Index is the number of the row containing the data to be returned.

MatchType defines whether the match has to be exact (False) or the nearest found (True).

Text matching is not case sensitive (even when using FALSE for an exact match).
Data

Ensure the data (in the Value field and also in the Table being searched) can be matched.

Spaces and non-printable characters are common causes of data mismatch.

This can happen frequently when table data is copied from another source, like a database table.

If the function returns a #VALUE! error, a data mismatch could be the cause.

See #VALUE! below for more information.

Examples

Rule

Meaning
DWHLookup(CarColourComboBoxReturn, DwLookupVehicles, 3, 2, FALSE)The function looks in the Vehicles table for a match, in the third row of the table, to the value returned from the CarColourComboBox.

If a match is found, the function then looks up to the second row and returns the value in the same column as the match found.

The user has also specified that the match needs to be exact (denoted by the FALSE term).

In this case, the Car Color selected in the combo box is "Blue", so the function returns "Golf".

Example Outcomes

Value

Table Name

Lookup Column

Result Column Index

MatchType

Outcome

"Blue"Vehicles32False (Exact)"Golf"
"White"Vehicles31False (Exact)"Renault"
"Bleu de France"Vehicles31True (Nearest)"Mazda"

See Matches and Nearest Matches - Strings below to learn why Mazda is returned.

"Mazerati"

Intentionally misspelled for the purpose of the example.

Vehicles13True (Nearest)"Black"

See Matches and Nearest Matches - Strings below to learn why Black is returned.

36People32True (Nearest)"Joe Bloggs"

See Matches and Nearest Matches - Strings below to learn why Joe Bloggs is returned.

42People34False (Exact)"Female"

Example Data

Vehicles Table

MakeVolkswagenFordRenaultMazdaMaserati
ModelGolfEscortKangoo2GranTurismo
ColourBlueRedWhiteBlackSilver

People Table

Member ID424496107251
NameDave SharpJoe BloggsSandra ShieldThomas KnightIsabelle Jones
Age2537422156
GenderMaleMaleFemaleMaleFemale

Error Results

#VALUE!

This error often occurs when the value to be found does not exist in the table.

Using the Vehicles Table (above) as the table the value is to be found in, examples of this include:

  • Value (to be found) = "Tesla"

    "Tesla" does not exist in the table.

    to resolve:

    Modify the table to include the missing value.

  • Value (to be found) = "Volkwagon"

    "Volkwagon" is spelled incorrectly and does not exist in the table.

    Similarly the entry in the table could have the incorrect spelling.

    to resolve:

    Ensure spellings are correct in the value filed and table values.

  • Value (to be found) = "Ford "

    "Ford " has a space at the end, where the table value does not.

    Similarly the entry in the table could have the extra space.

    To resolve:

    Ensure trailing spaces are removed.

    Consider using the Trim function to remove whitespace characters.

    The Trim functions will also remove additional spaces in between words.

    Additional spaces can be difficult to view, also other non printable characters (such as carriage returns) will not be displayed in the table.

    Finding and cleaning offending characters using a third party editor is recommended.

    Notepad++ allows all characters to be shown.

    Paste the data into Notepad++ and select View>Show Symbol>Show All Characters

    Remove all non printable characters and copy the data back into DriveWorks.

Matches and Nearest Matches

When considering how to search for a match, DriveWorks will take into consideration the data type of the value passed into the lookup.

Numeric Values

If the value passed into the lookup is a number, then DriveWorks will try to evaluate the values in the table as numbers for comparison purposes.

If the value being evaluated in the table cannot be converted into the same type as the value passed into the lookup, the table value will be considered non-matching.

When considering nearest matches for numeric values, DriveWorks will search the entire table column for the number that is closest to the Value in the first parameter of the lookup.

This behavior differs from the method that Microsoft Excel’s lookup functions employ.

With Excel’s range lookup approach for a nearest match, the table is searched until a value that is greater than the target value is found, and the last value less than the target value is returned.

With a table that is sorted, this means that you will always receive a value that is less than the target value.

DriveWorks searches the entire table, and will always return the closest value, whether it is less than or greater than the target value.

In the case where two values are equidistant from the search Value, DriveWorks will return the first occurrence, the cell closest to the left edge of the table.

Dates

DriveWorks compares dates in the same way, provided both the Value parameter, and the data in the table are formatted as dates.

When using the nearest match method (MatchType is TRUE), DriveWorks will find the date in the table that is closest to the Value in the first parameter.

This date may be before or after the provided Value.

If DriveWorks finds two dates equidistant from the Value parameter, the returned match will be the value closest to the left edge of the table.

Strings

When comparing strings, DriveWorks ignores case and tries to match the characters starting at the beginning of the string.

The nearest match is determined by the number of characters at the beginning of the string that match the Value parameter.

When multiple cells in the table column match the same number of characters at the beginning of the string, DriveWorks will do a nearest match to the first non-matching character in the string.

When we look at the examples above, we can see that searching the Vehicles table for "Maserati" will return "Silver" from the color column.

But, because we misspelled "Mazerati" in our second example, DriveWorks finds that "Mazda" has the first three letters matching our misspelled input value, while "Maserati" only shares the first two characters in common.

Therefore, DriveWorks returns "Black" from the color column as the nearest match.

The fact that the remainder of "Mazerati" matches "Maserati" is not considered.