column_ifexists()
Learn how to use the column_ifexists() function to return a reference to the column if it exists.
Displays the column, if the column exists. Otherwise, it returns the default column.
Syntax
column_ifexists(columnName,defaultValue)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| columnName | string | ✔️ | The name of the column to return. |
| defaultValue | scalar | ✔️ | The default column to return if columnName doesn’t exist in the table. This value can be any scalar expression. For example, a reference to another column. |
Returns
If columnName exists, then returns the column. Otherwise, it returns the defaultValue column.
Example
This example returns the default State column, because a column named Capital doesn’t exist in the StormEvents table.
StormEvents | project column_ifexists("Capital", State)
Output
This output shows the first 10 rows of the default State column.
| State |
|---|
| ATLANTIC SOUTH |
| FLORIDA |
| FLORIDA |
| GEORGIA |
| MISSISSIPPI |
| MISSISSIPPI |
| MISSISSIPPI |
| MISSISSIPPI |
| AMERICAN SAMOA |
| KENTUCKY |
| … |
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.