
The Worksheet Query menu command directs Origin to locate data in the active worksheet based on a user-specified conditional expression. The located data values are extracted. In other words, these values are copied and pasted to another worksheet, or, the cells that have these values are filled with a specified color or selected.
There are two main panels in this dialog: the left panel and the right panel.
Contents |
To query data from a worksheet, you can use the Worksheet Query tool. To bring up this tool, you can:
After entering the condition in the Condition box, click the OK or Apply button to perform the query.
The left panel lists all the columns in the active worksheet, with some basic information about them. You can check before the columns to select those that will be extracted. To see more information about the column, right-click on the panel area and select the quantities you want to see in the left panel. Menu commands available in the short-cut menu include the following:
| Extract |
Use this menu command to specify whether or not to show the Extract checkbox column. With these checkboxes, you can specify the columns that will be extracted. |
|---|---|
| Type |
Use this menu command to specify whether or not to show the column type. |
| Format |
Use this menu command to specify whether or not to show the column format. |
| 1st Value |
Use this menu command to specify whether or not to show the first column value. |
| Check all Extract |
Use this menu command to check all the checkboxes in the Extract column. |
| Uncheck all Extract |
Use this menu command to clear all the checkboxes in the Extract column. |
The right panel includes the condition edit box, output controls, and other controls.
Before querying data, you should select columns into this list, and these columns will be used to build the condition. To move columns to the list, select them on the left panel and then click the
button. Only when there are columns in this list is the Condition edit box editable.
There are two items on this table:
| Alias |
This allows you to define an alias for each column. Then you can use this alias to build the condition. To edit the alias, double-click on the cell, enter the new alias and click outside. |
|---|---|
| Column |
This is for displaying the column names. |
Type a conditional expression into the text box used to extract data. You can use any of the logical and relational operators listed below. Additionally, you can use any arithmetic operators (+, -, *, /, ^).
| Operators | Meanings |
|---|---|
|
> |
Greater than |
|
>= |
Greater than or equal to |
|
< |
Less than |
|
<= |
Less than or equal to |
|
== (or =) |
Equal to |
|
!= (NOT) |
Not equal to |
|
&& (AND) |
And |
|
| | (OR) |
Or |
Besides typing the conditional expression, you can also use the buttons beside the Condition edit box to build the condition.
When building conditions, you can use both the worksheet alias and Col() notation to specify a column in the expression. To indicate a row number, use the variable i. To continue an expression on the next line, press enter.
For example, to extract rows with values in column A that are greater than 0, you can type:
Col(A)>0
If you have specified an alias, for example, "Temperature" for column A, you can also use:
Temperature > 0
To query worksheet data using text criteria, use the following syntax:
Col(ColumnName)[i]$ == "text";
For example:
Col(Station)[i]$ == "Northwest";
|
Note: Origin uses a filter that is not case-sensitive, when it extracts data using text criteria. |
Click this button to test the condition. If any record is found, the total number of result rows will be shown in the Worksheet Query dialog and the corresponding rows will be highlighted in the source worksheet.
Specify the range of rows to be extracted.
| Add a column indicating True (1) or False (0) |
Add a new column to the source worksheet to indicate whether the condition is satisfied: 1 for "Yes" and 0 for "No". |
|---|---|
| Extract to a New Worksheet |
Extract the data to a new worksheet in the source workbook. |
| Extract to a New Workbook |
Extract the data to a new workbook. |
| Extract to Specified Sheet |
Extract the data to a specified worksheet. Once you have selected this option, you should specify the worksheet name in the Worksheet Name edit box and Column from edit box (its default is set to 1). |
| Fill with Specified Color |
Fill all cells found by the query with a specified color. |
| Select |
Select all cells found by the query. |
| Load Sample |
Load the built-in examples. |
|---|---|
| Load |
Load a saved condition. |
| Save |
Save the current condition. |
| Save As... |
Save the condition with a new name. |
Set LabTalk scripts that will be run before the data query. This will help to prepare proper data for the condition. You can set a Script Before Select Data Loop and a Script Before If Condition.
Origin actually runs the data query routine as follows:
Suppose there are two columns. Col(a) has some data. Col(b) contains three numbers which will be used as row indices of cells which will be extracted from Col(a).
We can set the Script Before Select Data Loop as follows:
j=1;
Then set the Script Before If Condition as:
if( i == col(b)[j] ) { temp = col(a)[i]; j++; }
Extract data in the worksheet with the following condition:
A == temp
After clicking the Test button, Origin will highlight row 1, 4, and 7.
|
Note: To use the scripts, the minimum version of Origin required is Origin 8.0 SR3. |
You can insert functions from a number of categorized lists, to build your query condition. Recently used functions are accessible from the submenu. This F(x) menu works the same to the one in the Set Values dialog.
These functions include: LabTalk functions and built-in Origin C functions.
To add a user-defined function in the F(x) selection, please refer to the How to Create a User-Defined Function for Set Column Values.
For more information of these functions, please refer to Script Accessible Functions in Appendix 3.