1

I have the following app insights query :

let someResult=
customEvents | where name in ('SomeAction')
| parse customDimensions.someId with someId 
| parse customDimensions.sometaskId with someTaskId
| parse user_AuthenticatedId with user
| summarize max(timestamp) by user, someId , someTaskId
| join (
customEvents | where name in ('someAction')
| parse customDimensions.action with someAction
| parse customDimensions.someId with someId
| project someAction,someId
) on someId
| join (
customEvents
| where name in ('someResult')
| parse customDimensions.someId with someId 
| parse customDimensions.someIdsWithSomething with sometaskIds
| parse array_length(split(customDimensions.someIdsWithSomething ,',')) with someTaskCount
| distinct someId , sometaskIds,someTaskCount
| where sometaskIds<> ''
) on someId 
| summarize sumif(todouble(someTaskCount),someAction=="accept")/sum(todouble(someTaskCount));

How can i divide someResult by something here . For example i want the final result to be someResult/10 . Thank you for the help.

kauschan
  • 446
  • 2
  • 8
  • 21
  • Check out the useful operators documentation https://learn.microsoft.com/en-us/azure/azure-monitor/log-query/useful-operators. –  Dec 11 '18 at 21:03
  • I did but i am unable to do a simple division which the doc says it allows :( – kauschan Dec 11 '18 at 21:05
  • In the query windows you can divide ```print 10/10``` –  Dec 11 '18 at 21:09
  • One other quick question what if i want to divide the results from 2 different variables . For example : someResult/someAnotherResult – kauschan Dec 11 '18 at 21:23
  • same concept ```let apple = 10; let orange = 10; print apple/orange``` –  Dec 11 '18 at 21:27
  • @Rthomas529 that works in your example but not if the assigned value is a query result. – Peter Bons Dec 11 '18 at 21:29
  • 1
    sure it does. Just assign the value of your query to a variable. –  Dec 11 '18 at 21:30
  • how can i just extract the result in that case ? – kauschan Dec 11 '18 at 21:30
  • 1
    @Rthomas592 I must be doing something wrong then because I get an error about not being able to convert it to a scalar or something like that (away from keyboard so I cannot tell the exact message) – Peter Bons Dec 11 '18 at 21:36
  • @Peter Bons : Yep converting to scalar and a simple print works . Thanks guys – kauschan Dec 11 '18 at 21:40

2 Answers2

2

Try this:

let someResult=
customEvents | where name in ('SomeAction')
| parse customDimensions.someId with someId 
| parse customDimensions.sometaskId with someTaskId
| parse user_AuthenticatedId with user
| summarize max(timestamp) by user, someId , someTaskId
| join (
customEvents | where name in ('someAction')
| parse customDimensions.action with someAction
| parse customDimensions.someId with someId
| project someAction,someId
) on someId
| join (
customEvents
| where name in ('someResult')
| parse customDimensions.someId with someId 
| parse customDimensions.someIdsWithSomething with sometaskIds
| parse array_length(split(customDimensions.someIdsWithSomething ,',')) with someTaskCount
| distinct someId , sometaskIds,someTaskCount
| where sometaskIds<> ''
) on someId 
| summarize summarized = sumif(todouble(someTaskCount),someAction=="accept")/sum(todouble(someTaskCount));
someResult 
| project summarized / 10

I could not test it since I do not have those custom dimensions but it is based from this working/tested example:

let someResult = requests
| summarize summarized = count();
someResult 
| project summarized / 10
Peter Bons
  • 26,826
  • 4
  • 50
  • 74
  • Yes this works . One other quick question what if i want to divide the results from 2 different variables . For example : someResult/someAnotherResult – kauschan Dec 11 '18 at 21:10
1

I hope this helps someone, as this SO question shows up as the top result but doesn't answer the question. I determined something like this from this answer:

let authRequests = requests | where operation_Name contains "Auth";
let countNon500s = toscalar(authRequests | where resultCode !startswith "5" | count);
let countAll = toscalar(authRequests | count);
let percent = 100*todouble(todouble(countNon500s) / todouble(countAll));
print todecimal(percent) 

The three important parts are:

  • you need to convert the values to scalar values (otherwise they are tables).
  • you need to convert the resulting percentage to doubles (otherwise they are 1 or 0)
  • you need to use 'print' to output to a tabular form (or extend a column)