Dashboards & Visualizations

Sum columns selected from a dropdown menu

ravikumar_sri20
Engager

I have a multi select drop down menu with field names as values.   

When i one or mone values from the drop down menu, those fields/columns need to totaled.

I tried the below code as sugged by Meta AI..But it is not producing any result. Please help me

<dashboard>
  <label>Sum Selected Fields</label>
  <row>
    <panel>
      <input type="dropdown" token="selected_fields">
        <label>Select Fields</label>
        <choice value="field1">Field 1</choice>
        <choice value="field2">Field 2</choice>
        <choice value="field3">Field 3</choice>
      </input>
      <chart>
        <search>

          | eval sum_fields="$selected_fields$"
          | stats sum(eval(split(sum_fields, ","))) as Total by Jobname
        </search>
      </chart>
    </panel>
  </row>
</dashboard>
Labels (1)
0 Karma
1 Solution

victor_menezes
Path Finder

Hi Ravi,

The strategy is to configure your multivalue input with using prefix, sufix and delimiter, like this:

<fieldset submitButton="false">
<input type="multiselect" token="field1">
<label>field1</label>
<choice value="value1">value1</choice>
<choice value="value2">value2</choice>
<choice value="value3">value3</choice>
<delimiter>,</delimiter>
<prefix>| stats sum(</prefix>
<suffix>)</suffix>
</input>
</fieldset>

Via UI it will look like this:

Screenshot 2024-10-17 161730.png

 

So in your search you'll simply do:

|makeresults $field1$

 

where |makeresults is your actual search. The token will append | sum(<selected_values>)

 

Then you can add the proper grouping fields and etc to make that happen as you want it to. (like add the "as Total by Jobname" after the ")" suffix

View solution in original post

0 Karma

ravikumar_sri20
Engager

Thank you so much Victor!!

0 Karma

victor_menezes
Path Finder

Hi Ravi,

The strategy is to configure your multivalue input with using prefix, sufix and delimiter, like this:

<fieldset submitButton="false">
<input type="multiselect" token="field1">
<label>field1</label>
<choice value="value1">value1</choice>
<choice value="value2">value2</choice>
<choice value="value3">value3</choice>
<delimiter>,</delimiter>
<prefix>| stats sum(</prefix>
<suffix>)</suffix>
</input>
</fieldset>

Via UI it will look like this:

Screenshot 2024-10-17 161730.png

 

So in your search you'll simply do:

|makeresults $field1$

 

where |makeresults is your actual search. The token will append | sum(<selected_values>)

 

Then you can add the proper grouping fields and etc to make that happen as you want it to. (like add the "as Total by Jobname" after the ")" suffix

0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...