Search code examples
azure-application-insightskql

Azure Application Insights KQL - How to accumulate values?


I would like to accumulate values by timestamp in a ever growing manner.

The following query

ContainerLog
| extend logsize = string_size(LogEntry)
| summarize sum(logsize) by bin(TimeGenerated, 1m)
| render timechart 

generates a graph that goes up and down: enter image description here I would like to add the previous value with the current value, this way generating an always growing graph symbolizing the total amount of requests up to that moment.


Solution

  • // Sample data generation. Not part of the solution.
    let ContainerLog = materialize(range i from 1 to 15 step 1 | extend TimeGenerated = ago(7d*rand()), logsize = rand(1000));
    // Solution starts here.
    ContainerLog
    | summarize sum(logsize) by bin(TimeGenerated, 1m)
    | order by TimeGenerated asc
    | extend accumulated_sum_logsize = row_cumsum(sum_logsize)
    | render timechart
    

    Graph

    Fiddle

    P.S.
    I kept sum_logsize for learning purposes.
    In your scenario it can be removed.