# Lens Line Chart - Average of Sum of Fields Per Session

**URL:** <https://discuss.elastic.co/t/lens-line-chart-average-of-sum-of-fields-per-session/360028>\
**Category:** Kibana\
**Tags:** visualisation\
**Created:** [May 22, 2024, 9:05pm UTC](https://discuss.elastic.co/t/lens-line-chart-average-of-sum-of-fields-per-session/360028 "2024-05-22T21:05:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sfageol](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sfageol](https://discuss.elastic.co/u/sfageol)\
**Post date:** [May 22, 2024, 9:05pm UTC](https://discuss.elastic.co/t/lens-line-chart-average-of-sum-of-fields-per-session/360028/1 "2024-05-22T21:05:15Z")

</div>

I want a line chart that shows the average length of a web session. The issue is that we are logging the numeric value in 4 separate parts with no total logged. Here are my fields per log line:

SessionID = 123  
Resource = Jump  
Length = .038

SessionID = 123  
Resource = Run  
Length = .027

SessionID = 123  
Resource = Swim  
Length = .056

So each SessionID has 3-4 different log lines. I want the sum of Length on all log lines per session - giving me a total length for the session. Then I want to display the average of all of the sessions in the line chart.

Any ideas?

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [May 23, 2024, 3:06pm UTC](https://discuss.elastic.co/t/lens-line-chart-average-of-sum-of-fields-per-session/360028/2 "2024-05-23T15:06:59Z")

</div>

Hi @sfageol

In the example above, you want a `SessionID: 123` series that is `.038 + .027 + .056` at `t0`, correct?

---

<div class="post-metadata">

**Author:** ![sfageol](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sfageol](https://discuss.elastic.co/u/sfageol)\
**Post date:** [May 23, 2024, 4:52pm UTC](https://discuss.elastic.co/t/lens-line-chart-average-of-sum-of-fields-per-session/360028/3 "2024-05-23T16:52:15Z")

</div>

I'll try to clarify. Each of these groups of 3 is a log line:

SessionID = 123  
Resource = Jump  
Length = .038

SessionID = 123  
Resource = Run  
Length = .027

SessionID = 123  
Resource = Swim  
Length = .056

SessionID = 999  
Resource = Jump  
Length = .055

SessionID = 999  
Resource = Run  
Length = .076

SessionID = 999  
Resource = Swim  
Length = .039

I want to sum the 3 lengths for each SessionID:

SessionID 123 = .038+.027+.056  
SessionID 999 = .055+.076+.039

And then display the average of the totals on a line chart.

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [May 24, 2024, 8:12am UTC](https://discuss.elastic.co/t/lens-line-chart-average-of-sum-of-fields-per-session/360028/4 "2024-05-24T08:12:54Z")

</div>

I see.  
One last question: each entry there has a timestamp, right? For each session how long would be the span of it?

Is it something like a daily session and the line chart should see how the session total length changed over time?

---

<div class="post-metadata">

**Author:** ![sfageol](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sfageol](https://discuss.elastic.co/u/sfageol)\
**Post date:** [May 24, 2024, 11:56am UTC](https://discuss.elastic.co/t/lens-line-chart-average-of-sum-of-fields-per-session/360028/5 "2024-05-24T11:56:10Z")

</div>

The timespan is extremely short. This is an iFrame and I want the line chart to show how long it takes to load the iFrame. So typically the total time span should be under a second or two but possibly a bit more.

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [May 24, 2024, 12:07pm UTC](https://discuss.elastic.co/t/lens-line-chart-average-of-sum-of-fields-per-session/360028/6 "2024-05-24T12:07:45Z")

</div>

mm ok.  
Do you mind sketch the final chart result? Just to be sure we're talking about the same thing

---

<div class="post-metadata">

**Author:** ![sfageol](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sfageol](https://discuss.elastic.co/u/sfageol)\
**Post date:** [May 24, 2024, 12:19pm UTC](https://discuss.elastic.co/t/lens-line-chart-average-of-sum-of-fields-per-session/360028/7 "2024-05-24T12:19:08Z")

</div>

End goal is something like this:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/d/4dee4106c511ac55934f730a2632a10b103fc96b.png)

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [May 24, 2024, 1:17pm UTC](https://discuss.elastic.co/t/lens-line-chart-average-of-sum-of-fields-per-session/360028/8 "2024-05-24T13:17:36Z")

</div>

I think what you can do is the following in Lens:

- configure a Line chart for one layer
- configure a date histogram over the Horizontal axis
- configure a metric over the Vertical Axis as:

```auto
sum(Length, kql='Resource: Jump) + sum(Length, kql='Resource: Run') + sum(Length, kql='Resource: Swim')

```

- configure a break down by `SessionID` and then configure a `collapse by: Average`
- now duplicate the layer (top right -\> Duplicate layer)
- tune the Break down dimension in the new layer by `SessionID` and then configure a `collapse by: Max`
