最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

azure - Kql replace column value if it is empty in a query - Stack Overflow

programmeradmin4浏览0评论

I have a query like:

customers
|order by updateTime desc
| project id,updateTime,name,updated,status
| take 1

Which returns several columns, including status column being String. This field can be Null or with some status info.

Let tempStatus= Status | where id='1'| project status

I want to set the query from Customer table to return latest row and if the status column is empty, then replace it with my tempStatus. How do I do this? I tried iif but it's not letting me inside the query..

Anyone can help?

I have a query like:

customers
|order by updateTime desc
| project id,updateTime,name,updated,status
| take 1

Which returns several columns, including status column being String. This field can be Null or with some status info.

Let tempStatus= Status | where id='1'| project status

I want to set the query from Customer table to return latest row and if the status column is empty, then replace it with my tempStatus. How do I do this? I tried iif but it's not letting me inside the query..

Anyone can help?

Share Improve this question edited Mar 27 at 11:21 David דודו Markovitz 45.2k7 gold badges74 silver badges94 bronze badges asked Mar 26 at 2:19 user3822558user3822558 816 bronze badges 1
  • could you please share what you have tried – Balaji Commented Mar 26 at 2:33
Add a comment  | 

2 Answers 2

Reset to default 1

Adding to @Yoni L.'s answer, you can also try the below KQL query which shown as below:

let tempStatus = datatable(id: string, status: string)
[
    "8", "Active"
];
let RithCustomer = datatable(id: string, updateTime: datetime, name: string, updated: string, status: string)
[
    "8", datetime(2025-03-25 10:00:00), "Rithwik", "Yes", "",
    "7", datetime(2025-03-24 15:30:00), "Bojja", "No", "Inactive"
];
RithCustomer
| order by updateTime desc
| extend teststatus = toscalar(tempStatus | where id == "8" | project status)
| project id, updateTime, name, updated, status = iff(status == "", teststatus, status)
| take 1

Output:

Fiddle.

Try using the coalesce() function

发布评论

评论列表(0)

  1. 暂无评论