A more flexible lookup function — XLOOKUP
In DingTalk Spreadsheet, use the XLOOKUP function to perform lookups and matching. Compared with the existing lookup functions (LOOKUP, VLOOKUP, HLOOKUP), XLOOKUP is more flexible and faster.XLOOKUP overview
The XLOOKUP function searches for a “target value” within a “lookup range”. When the lookup succeeds, it returns the data at the corresponding position in the “result range”, based on the position of the match within the “lookup range”. XLOOKUP has 6 parameters, in order:- Target value (required)
- Lookup range (required)
- Result range (required)
- The result to return when the target value is not found
- Match type
- Search mode
”Lookup range” and “result range” can be anywhere
The existing lookup functions require the “result range” to be to the right of or below the “lookup range”, which can be inconvenient in some scenarios. In the XLOOKUP function, the “lookup range” and the “result range” are independent parameters (the 2nd and 3rd parameters), removing constraints on the structure of the source data: Example: Searching for “Orange” within the range B2:B5 finds the match at position 2, so the result is the 2nd value in the range A2:A5, “dd231”. The XLOOKUP function has no notion of “lookup direction” and requires the “lookup range” to be a single row or single column. The function returns the value at the same position in the result range as the matched row/column. For example: Example: Searching for “Unit price” within the range A1:D1 finds the match at position 3, so the result is the 3rd value in the range A3:D3, 2.3.Default result when no match is found
When the target value is not found, the existing lookup functions return the #N/A error. With XLOOKUP, you can specify a default value (the 4th parameter), which is returned when the target value is not found: Example: If “Cherry” is not found within the range B2:B5, the function returns the 4th parameter as the result.More precise lookup modes
The 5th and 6th parameters of the XLOOKUP function are “match type” and “search mode”. Combine them to specify more precise lookup behavior.
For example, find the product closest to the target sales amount:
Example: With the 5th parameter set to -1, the function looks for 100 or the largest value smaller than 100. The matching value 77 is found within the range D2:D5, so the corresponding result “Watermelon” is returned.