Dashboards & Visualizations

How to set token from specific row & field in a table?

htrednek
Explorer

Ok, so I'm trying to consolidate some searches and one sticking point is that I've got an ugly base search chased by another doing an appendpipe to give me a summary row. Ideally I'd like it to be one search, however, I need to set tokens from the values in the summary but cannot seem to make that happen outside of the separate search.
I know it uses the $result.fieldname$ method and drilldowns use $row.column$. I'm kinda hoping there's a hybrid to specify the row# or last row specifically using the $result.xxx$ style. (If there is, I can 't get the syntax correct...)

<search id="bigolquery">
    <query> yadda yadda </query>
</search>
<search id="bigolsumm" base="bigoldquery">
    <query> 
        | appendpipe [ stats sum(fld1) as fld1 sum(fld2) as fld2 
        | eval fldavg=round(fld1/fld2*100,1)]
    </query>
    <done>
        <set token="fld1val">$result.fld1$</set>
        <set token="fld2val">$result.fld2$</set>
        <set token="fldavgval">$result.fldavg$</set>
    </done>
</search>
1 Solution

woodcock
Esteemed Legend

Add this:

... | eventstats last(xxx) AS _last_xxx

Then every row has an invisible field called _last_xxx with the last value of xxx so you can then use $result._last_xxx$.

View solution in original post

woodcock
Esteemed Legend

Add this:

... | eventstats last(xxx) AS _last_xxx

Then every row has an invisible field called _last_xxx with the last value of xxx so you can then use $result._last_xxx$.

htrednek
Explorer

This works perfectly. Thank you!

niketn
Legend

@htrednek the default token $result.<fieldname>$ fetches the first row of result. So crooked way would be you use | reverse in your subsearch and your last row will become first row. Hence the $result.<fieldname>$ token will access the value from the last row.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

somesoni2
Revered Legend

Are you using bigolsumm query in any visualization Or it's just for setting the token?

0 Karma

htrednek
Explorer

yes. It's displayed as part of the table as well as setting the tokens.

0 Karma

somesoni2
Revered Legend

Ok.... as far as I know, you can't set tokens from specific row number in the table. What you can do is create another search which is not used in any visualization but is using base="bigoldquery" and running your appendpipe stats are regular stats. The purpose of this search will be just to set tokens.

<search id="bigolsummtok" base="bigoldquery">
     <query> 
         |  stats sum(fld1) as fld1 sum(fld2) as fld2 
         | eval fldavg=round(fld1/fld2*100,1)
     </query>
     <done>
         <set token="fld1val">$result.fld1$</set>
         <set token="fld2val">$result.fld2$</set>
         <set token="fldavgval">$result.fldavg$</set>
     </done>
 </search>
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...