user989988
user989988

Reputation: 3736

Kusto Query Percentage Calculation showing incorrect data

I have the following kusto query to find out som differece in 2 columns:

customEvents
| where name == "Nulls"
| project timestamp,    
    Column = tostring(customDimensions["Column"]),
    CurrentNull = toint(customDimensions["CurrentNull"]),
    PreviousNull = toint(customDimensions["PreviousNull"]),
    CurrentRows = toint(customDimensions["CurrentRows"]),
    PreviousRows = toint(customDimensions["PreviousRows"])    
| distinct timestamp, Column, CurrentNull, PreviousNull, CurrentRows, PreviousRows
| extend Delta = CurrentNull - PreviousNull,
         CurrentNullPercent = (CurrentNull/CurrentRows) * 100,
         PreviousNullPercent = (PreviousNull/PreviousRows) * 100
| distinct timestamp, Column, CurrentNull, PreviousNull, Delta, CurrentNullPercent, CurrentRows
| order by Delta desc

enter image description here

I notice that the CurrentNullPercent value is not correct. For example, 12,517/352393 * 100 should be 3 and it is displayed as 0. What am I missing?

Upvotes: 1

Views: 218

Answers (1)

David דודו Markovitz
David דודו Markovitz

Reputation: 44941

Integer arithmetic

Arithmetic without fractions. A computer performing integer arithmetic ignores any fractions that are derived. For example, 8 divided by 3 would yield the whole number 2.

Use

(1.0 * CurrentNull / CurrentRows) * 100

Or

(toreal(CurrentNull) / CurrentRows) * 100

Upvotes: 1

Related Questions