你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。

iff()

使用 “版本 ”下拉列表切换服务。 了解有关导航的详细信息。
适用于: ✅ Microsoft Fabric ✅ Azure 数据资源管理器 ✅ Azure Monitor ✅ Microsoft Sentinel

当 then 条件的计算结果为 if时返回 true 值,否则返回 else 值。

iff() 和 iif() 函数等效。

语法

iff( if , then , else )

详细了解语法约定。

参数

名字 类型 必填 描述
if string ✔️ 计算结果为布尔值的表达式。
then 标量 ✔️ 当 if 条件的计算结果为 true时返回其值的表达式。
else 标量 ✔️ 当 if 条件的计算结果为 false时返回其值的表达式。

返回

当 then 条件计算结果为 if时,此函数返回 true 值,否则返回 else 值。

例子

使用 iff() 对数据进行分类

以下查询使用 iff() 函数根据其事件类型将风暴事件分类为“雨事件”或“未下雨事件”,然后投影状态、事件 ID、事件类型和新的降雨类别。

StormEvents
| extend Rain = iff((EventType in ("Heavy Rain", "Flash Flood", "Flood")), "Rain event", "Not rain event")
| project State, EventId, EventType, Rain

输出

下表仅显示前五行。

州 EventId EventType 雨
大西洋南部 61032 Waterspout 不下雨事件
佛罗里达州 60904 大雨 雨事件
佛罗里达州 60913 龙卷风 不下雨事件
格鲁吉亚 64588 雷雨风 不下雨事件
密西西比州 68796 雷雨风 不下雨事件
... ... ... ...

将 iff() 与其他函数组合

以下查询计算作物和财产造成的总损失,根据总损坏、直接伤害和直接死亡对风暴事件的严重性进行分类,然后按严重性汇总事件总数和事件数。

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

输出

严厉 TotalEvents
低 54805
高 977
温和 3284