How can I return results of a query that aren’t in the results of another query? For example, I want to return the results that are returned from the first query and are not also in the second query:
First query:
customEvents
| extend Product = tostring(customDimensions.["Is Successful"])
| extend TransactionNumber = tostring(customDimensions.["Transaction Number"])
| extend StoreCode = tostring(customDimensions.["StoreCode"])
| where name contains 'Transaction Posted' and customDimensions.['Transaction Number'] != ''
| where customDimensions.["Is Successful"] == "False"
| project TransactionNumber
e.g. if the above returned
145
167
100
94
56
Second query:
customEvents
| extend Product = tostring(customDimensions.["Is Successful"])
| extend TransactionNumber = tostring(customDimensions.["Transaction Number"])
| extend StoreCode = tostring(customDimensions.["StoreCode"])
| where name contains 'Transaction Posted' and customDimensions.['Transaction Number'] != ''
| where customDimensions.["Is Successful"] == "True"
| project TransactionNumber
e.g. if the above returned
94
95
96
97
167
100
I want the result set to be:
145
56
I’ve tried the following but that doesn’t appear to return the results from the failures query that aren’t in the results of the successes query:
let failures = (customEvents
| extend Product = tostring(customDimensions.["Is Successful"])
| extend TransactionNumber = tostring(customDimensions.["Transaction Number"])
| extend StoreCode = tostring(customDimensions.["StoreCode"])
| where name contains 'Transaction Posted' and customDimensions.['Transaction Number'] != ''
| where customDimensions.["Is Successful"] == "False"
| project TransactionNumber);
let successes = (customEvents
| extend Product = tostring(customDimensions.["Is Successful"])
| extend TransactionNumber = tostring(customDimensions.["Transaction Number"])
| extend StoreCode = tostring(customDimensions.["StoreCode"])
| where name contains 'Transaction Posted' and customDimensions.['Transaction Number'] != ''
| where customDimensions.["Is Successful"] == "True"
| project TransactionNumber);
failures
| join kind=fullouter (successes) on TransactionNumber
| where isnull(TransactionNumber)
| project TransactionNumber
2
Answers
Try doing an
anti-join
:Mark the whole code and execute it.
You can integrate your query like below KQL Query:
Output:
Fiddle.