SOLVED

Need help with a query with multiple if/thens

Iron Contributor

So I'm having a hard time coming up with a query that will get me the intended results. Any help would be appreciated.

 

My data looks like this:

Computer ID
SERVER-A12345
SERVER-A 
SERVER-A67890
SERVER-B 
SERVER-C 
SERVER-C34567

 

What I'm trying to get in a result:

  • If Computer has an ID or multiple IDs, return those rows but not the blanks
  • If Computer has ONLY blank ID, then return that row.

Expected Result:

ComputerID
SERVER-A12345
SERVER-A67890
SERVER-B 
SERVER-C34567

 

I'm sure I'm missing something simple... 

2 Replies
best response confirmed by Scott Allison (Iron Contributor)
Solution

@Scott Allison 
I'm not sure if I missed the 'simple' as well, but this works, using the datatable!

datatable (Computer:string,ID:string)
[
'SERVER-A','12345',
'SERVER-A','',
'SERVER-A','67890',
'SERVER-B','',	 
'SERVER-C','', 
'SERVER-C','34567'
]
| summarize countif(toreal(ID) > 1), make_set(Computer),make_set_if(ID, isnotempty(ID)) by Computer 
| summarize by Computer, tostring(set_ID)
| extend set_ID = iif(set_ID == '[]',' ',set_ID)
| mv-expand ID=todynamic(set_ID) to typeof(string)
| project-away set_ID

 

Screenshot 2021-03-10 092536.jpg

This is exactly what I needed (not the datatable part, though :) )!

Thanks again as always, Clive!
1 best response

Accepted Solutions
best response confirmed by Scott Allison (Iron Contributor)
Solution

@Scott Allison 
I'm not sure if I missed the 'simple' as well, but this works, using the datatable!

datatable (Computer:string,ID:string)
[
'SERVER-A','12345',
'SERVER-A','',
'SERVER-A','67890',
'SERVER-B','',	 
'SERVER-C','', 
'SERVER-C','34567'
]
| summarize countif(toreal(ID) > 1), make_set(Computer),make_set_if(ID, isnotempty(ID)) by Computer 
| summarize by Computer, tostring(set_ID)
| extend set_ID = iif(set_ID == '[]',' ',set_ID)
| mv-expand ID=todynamic(set_ID) to typeof(string)
| project-away set_ID

 

Screenshot 2021-03-10 092536.jpg

View solution in original post