Dashboards & Visualizations

addtotals result move to the top row

viktoriiants
Explorer

The query produces multiple pages of results. How do I move the total to the top (first) row for convenience?

 

search query | eval dayOfWeek=strftime(_time, "%A"), date=strftime(_time, "%Y-%m-%d") | eval dayNum=case(dayOfWeek=="Sunday", 1, dayOfWeek=="Monday", 2, dayOfWeek=="Tuesday", 3, dayOfWeek=="Wednesday", 4, dayOfWeek=="Thursday", 5, dayOfWeek=="Friday", 6, dayOfWeek=="Saturday", 7) | stats count as "Session count" by dayOfWeek, date | addtotals col=t row=f label="Month total" |sort date desc

 

Labels (2)
0 Karma
1 Solution

danspav
SplunkTrust
SplunkTrust

Hi @viktoriiants.,

How about something like this:

index=_internal 
| eval dayOfWeek=strftime(_time, "%A"), date=strftime(_time, "%Y-%m-%d") 
| eval dayNum=tonumber(strftime(_time,"%w")) + 1 ``` 1=Sunday, ..., 7=Saturday```
| stats count as "Session count" by dayOfWeek, date 
| addtotals col=t row=f
| eval sort = if(isnull(date),1,0)
| sort - sort + date 
| fields - sort

Here we're creating a new temporary field to sort on, where we set it to 1 for our total row, and 0 for all other rows. Then we sort by this column and the date column. Finally, we remove the "sort" column.

View solution in original post

danspav
SplunkTrust
SplunkTrust

Hi @viktoriiants.,

How about something like this:

index=_internal 
| eval dayOfWeek=strftime(_time, "%A"), date=strftime(_time, "%Y-%m-%d") 
| eval dayNum=tonumber(strftime(_time,"%w")) + 1 ``` 1=Sunday, ..., 7=Saturday```
| stats count as "Session count" by dayOfWeek, date 
| addtotals col=t row=f
| eval sort = if(isnull(date),1,0)
| sort - sort + date 
| fields - sort

Here we're creating a new temporary field to sort on, where we set it to 1 for our total row, and 0 for all other rows. Then we sort by this column and the date column. Finally, we remove the "sort" column.

viktoriiants
Explorer

Thank you! It did help 

0 Karma

meetmshah
Contributor

Hello, Just checking through if the issue was resolved or you have any further questions? 

0 Karma

viktoriiants
Explorer

Thank you

0 Karma

meetmshah
Contributor

Hello @viktoriiants, How about sorting it by 'Session count' before date desc?

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...