Splunk Search

How to write subquery in splunk

geetanjali
Path Finder

Hello,

I am drawing a view having one table. My table has two columns host and max(power). I want to add one more column which has latest value of the particular host. My module is :

<module name="HiddenSearch" layoutPanel="panel_row2_col2" group="Power Usage" autoRun="True">
    <param name="search">index="test" sourcetype="power_test"[search index="test" sourcetype="power_test" | chart max(Power) as powerc over host | sort -Date,-Time] | fields powerc | chart max(Power),max(powerc) over host | sort 10 -max(Power)</param>
    <param name="groupLabel">Power Usage</param>
    <module name="ViewstateAdapter">
        <module name="HiddenFieldPicker">
        <param name="strictMode">True</param>
        <module name="JobProgressIndicator">
          <module name="EnablePreview">
            <param name="enable">True</param>
            <param name="display">False</param>
            <module name="SimpleResultsTable">
              <param name="allowTransformedFieldSelect">True</param>
            </module>
          </module>
        </module>


      </module>
    </module>
</module>

I am trying to write sub-query which will return latest value of a particular host. That's why i am trying to sort by date and time.

But query is giving zero results. Please correct me.

Thanks in advance,

Geetanjali

Tags (2)
0 Karma

bwooden
Splunk Employee
Splunk Employee

I think you may do it all in one search for this use case:

    index="test" sourcetype="power_test" 
| chart max(Power) as max_power first(Power) as recent_power over host 
| sort 10 -max(Power)
0 Karma
Get Updates on the Splunk Community!

Updated Data Type Articles, Anniversary Celebrations, and More on Splunk Lantern

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

A Prelude to .conf25: Your Guide to Splunk University

Heading to Boston this September for .conf25? Get a jumpstart by arriving a few days early for Splunk ...

4 Ways the Splunk Community Helps You Prepare for .conf25

.conf25 is right around the corner, and whether you’re a first-time attendee or a seasoned Splunker, the ...