SOLVED

Need help with a query with multiple if/thens

%3CLINGO-SUB%20id%3D%22lingo-sub-2197892%22%20slang%3D%22en-US%22%3ENeed%20help%20with%20a%20query%20with%20multiple%20if%2Fthens%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2197892%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20I'm%20having%20a%20hard%20time%20coming%20up%20with%20a%20query%20that%20will%20get%20me%20the%20intended%20results.%20Any%20help%20would%20be%20appreciated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20data%20looks%20like%20this%3A%3C%2FP%3E%3CTABLE%20border%3D%221%22%20width%3D%22100%25%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%2250%25%22%20height%3D%2229px%22%3E%3CSTRONG%3EComputer%20%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%20width%3D%2250%25%22%20height%3D%2229px%22%3E%3CSTRONG%3EID%3C%2FSTRONG%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20height%3D%2229px%22%3ESERVER-A%3C%2FTD%3E%3CTD%20height%3D%2229px%22%3E12345%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20height%3D%2229px%22%3ESERVER-A%3C%2FTD%3E%3CTD%20height%3D%2229px%22%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESERVER-A%3C%2FTD%3E%3CTD%3E67890%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESERVER-B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESERVER-C%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ESERVER-C%3C%2FTD%3E%3CTD%3E34567%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I'm%20trying%20to%20get%20in%20a%20result%3A%3C%2FP%3E%3CUL%3E%3CLI%3EIf%20Computer%20has%20an%20ID%20or%20multiple%20IDs%2C%20return%20those%20rows%20but%20not%20the%20blanks%3C%2FLI%3E%3CLI%3EIf%20Computer%20has%20ONLY%20blank%20ID%2C%20then%20return%20that%20row.%3C%2FLI%3E%3C%2FUL%3E%3CP%3EExpected%20Result%3A%3C%2FP%3E%3CTABLE%20border%3D%221%22%20width%3D%22100%25%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%2250%25%22%20height%3D%2229px%22%3E%3CSTRONG%3EComputer%3C%2FSTRONG%3E%3C%2FTD%3E%3CTD%20width%3D%2250%25%22%20height%3D%2229px%22%3E%3CSTRONG%3EID%3C%2FSTRONG%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20height%3D%2229px%22%3ESERVER-A%3C%2FTD%3E%3CTD%20height%3D%2229px%22%3E12345%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20height%3D%2229px%22%3ESERVER-A%3C%2FTD%3E%3CTD%20height%3D%2229px%22%3E67890%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20height%3D%2229px%22%3ESERVER-B%3C%2FTD%3E%3CTD%20height%3D%2229px%22%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20height%3D%2229px%22%3ESERVER-C%3C%2FTD%3E%3CTD%20height%3D%2229px%22%3E34567%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20sure%20I'm%20missing%20something%20simple...%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2197892%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELog%20Analytics%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EQuery%20Language%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2198896%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20a%20query%20with%20multiple%20if%2Fthens%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2198896%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F151992%22%20target%3D%22_blank%22%3E%40Scott%20Allison%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3EI'm%20not%20sure%20if%20I%20missed%20the%20'simple'%20as%20well%2C%20but%20this%20works%2C%20using%20the%20datatable!%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-cpp%22%3E%3CCODE%3Edatatable%20(Computer%3Astring%2CID%3Astring)%0A%5B%0A'SERVER-A'%2C'12345'%2C%0A'SERVER-A'%2C''%2C%0A'SERVER-A'%2C'67890'%2C%0A'SERVER-B'%2C''%2C%20%20%0A'SERVER-C'%2C''%2C%20%0A'SERVER-C'%2C'34567'%0A%5D%0A%7C%20summarize%20countif(toreal(ID)%20%26gt%3B%201)%2C%20make_set(Computer)%2Cmake_set_if(ID%2C%20isnotempty(ID))%20by%20Computer%20%0A%7C%20summarize%20by%20Computer%2C%20tostring(set_ID)%0A%7C%20extend%20set_ID%20%3D%20iif(set_ID%20%3D%3D%20'%5B%5D'%2C'%20'%2Cset_ID)%0A%7C%20mv-expand%20ID%3Dtodynamic(set_ID)%20to%20typeof(string)%0A%7C%20project-away%20set_ID%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot%202021-03-10%20092536.jpg%22%20style%3D%22width%3A%20362px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F262427iE852CBAC46A56DAE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screenshot%202021-03-10%20092536.jpg%22%20alt%3D%22Screenshot%202021-03-10%20092536.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent 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 (Frequent 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!