title | description | ms.reviewer | ms.topic | ms.date |
---|---|---|---|---|
sumif() (aggregation function) |
Learn how to use the sumif() (aggregation function) function to calculate the sum of an expression value in records for which the predicate evaluates to true. |
alexans |
reference |
11/13/2023 |
Calculates the sum of expr in records for which predicate evaluates to true
.
[!INCLUDE ignore-nulls]
[!INCLUDE data-explorer-agg-function-summarize-note]
You can also use the sum() function, which sums rows without predicate expression.
sumif(
expr,
predicate)
[!INCLUDE syntax-conventions-note]
Name | Type | Required | Description |
---|---|---|---|
expr | string |
✔️ | The expression used for the aggregation calculation. |
predicate | string |
✔️ | The expression used to filter rows. If the predicate evaluates to true , the row will be included in the result. |
Returns the sum of expr for which predicate evaluates to true
.
This example shows the sum total damage for storms without casualties.
[!div class="nextstepaction"] Run the query
StormEvents
| summarize DamageNoCasualties=sumif((DamageCrops+DamageProperty),(DeathsDirect+DeathsIndirect)==0) by State
Output
The results table shown includes only the first 10 rows.
State | DamageNoCasualties |
---|---|
TEXAS | 242638700 |
KANSAS | 407360000 |
IOWA | 135353700 |
ILLINOIS | 120394500 |
MISSOURI | 1096077450 |
GEORGIA | 1077448750 |
MINNESOTA | 230407300 |
WISCONSIN | 241550000 |
NEBRASKA | 70356050 |
NEW YORK | 58054000 |
... | ... |
This example shows the sum of the birth dates for all names that have more than 4 letters.
let T = datatable(name:string, day_of_birth:long)
[
"John", 9,
"Paul", 18,
"George", 25,
"Ringo", 7
];
T
| summarize sumif(day_of_birth, strlen(name) > 4)
Output
sumif_day_of_birth |
---|
32 |