Subtracting two lines in vega chart

Hi, I am trying to create a chart which shows some kind of risk. The logic behind is that I have an index which has Dalue, startDate and endDate. I would like to show the line which is cumulative sum of value with startdate substracted by the same value but with enddate. I am only able to show value with only one of this date. Here is my code:

{
  $schema: https://vega.github.io/schema/vega-lite/v4.json
  data: {
# URL object is a context-aware query to Elasticsearch
    url: {
      %context%: true
      %timefield%: startDate
      index: nebula
      body: {
        size: 10000
        _source: [
          startDate
          Value
          endDate
        ]
      }
    }
# We only need the content of hits.hits array
    format: {
      property: hits.hits
    }
  }
#Parse timestamp into a javascript date value
  selection: {
    brush: {"type": "interval", "encodings": ["x"], "bind": "scales"}}
  mark: {
    type: line
    point: true
  }
  encoding: {
    x: {
      field: _source.startDate
      type: temporal
      timeUnit: "day"
      zoom: true
      bin: {"maxbins": 100 , "extent": {"selection": "brush"}}
      axis: {
        title: Date
        format: "%Y-%m-%d"
        labelAngle: -45
        labelOverlap: true
      }
    }
    y: {
      field: _source.Value
      type: "quantitative"
      aggregate: "sum"
      axis: {
        title: Risk
      }
    }
  }
}

I would appreciate any kind of help!

> Blockquote

A lot has changed since 2017 and I would answer this question differently now. I would recommend using formulas in Lens

Have you tried using vega-lite transforms for your calculations?

The thing is, I need the zooming future which kibana chart does not provide. I do not know how to use vega-lite transforms to create a new value/line which is subtraction of two cumulative sum of the same value from two different dates which are in the index record. Do you have any idea?