iff()
Applies to: ✅ Microsoft Fabric ✅ Azure Data Explorer ✅ Azure Monitor ✅ Microsoft Sentinel
Returns the then value when the if condition evaluates to true
, otherwise it returns the else value.
The
iff()
andiif()
functions are equivalent.
Syntax
iff(
if,
then,
else)
Learn more about syntax conventions.
Parameters
Name | Type | Required | Description |
---|---|---|---|
if | string |
✔️ | An expression that evaluates to a boolean value. |
then | scalar | ✔️ | An expression that returns its value when the if condition evaluates to true . |
else | scalar | ✔️ | An expression that returns its value when the if condition evaluates to false . |
Returns
This function returns the then value when the if condition evaluates to true
, otherwise it returns the else value.
Examples
Classify data using iff()
The following query uses the iff()
function to categorize storm events as either "Rain event" or "Not rain event" based on their event type, and then projects the state, event ID, event type, and the new rain category.
StormEvents
| extend Rain = iff((EventType in ("Heavy Rain", "Flash Flood", "Flood")), "Rain event", "Not rain event")
| project State, EventId, EventType, Rain
Output
The following table shows only the first five rows.
State | EventId | EventType | Rain |
---|---|---|---|
ATLANTIC SOUTH | 61032 | Waterspout | Not rain event |
FLORIDA | 60904 | Heavy Rain | Rain event |
FLORIDA | 60913 | Tornado | Not rain event |
GEORGIA | 64588 | Thunderstorm Wind | Not rain event |
MISSISSIPPI | 68796 | Thunderstorm Wind | Not rain event |
... | ... | ... | ... |
Combine iff() with other functions
The following query calculates the total damage from crops and property, categorizes the severity of storm events based on total damage, direct injuries, and direct deaths, and then summarizes the total number of events and the number of events by severity.
StormEvents
| extend TotalDamage = DamageCrops + DamageProperty
| extend Severity = iff(TotalDamage > 1000000 or InjuriesDirect > 10 or DeathsDirect > 0, "High", iff(TotalDamage < 50000 and InjuriesDirect == 0 and DeathsDirect == 0, "Low", "Moderate"))
| summarize TotalEvents = count(), SeverityEvents = count() by Severity
Output
Severity | TotalEvents |
---|---|
Low | 54805 |
High | 977 |
Moderate | 3284 |