Dashboards & Visualizations

How to compare two tables with different time range?

Mrig342
Contributor

Hi All,

I have got the below query at two different time range (Last 24 hrs and All Time).

index=* | stats count by index,host 

which gives a table as below:

index host count
abc hdcgcgmefla02uv 127976

 

Now I want to compare the host column in both the tables and populate it in a new column in a tabular view. If host is available in both time ranges, then the value is "Availabe" and if host is not available in any of the  time ranges the value will be "Not Available" Like below:

index host Comparision
abc hdcgcgmefla02uv Available
abc hdcgcgmefla22uv Not Available
xyz hdcgcgmefla12uv Available

 

Please help to create a query to get the table with the desired comparisons. Your kind inputs are highly appreciated.

Thank you..!!

Labels (1)
0 Karma
1 Solution

isoutamo
SplunkTrust
SplunkTrust

Hi

Here is one example how you could do it

index=* ``` This is not a best practices, try to define used indexes```
| eval TP = if (_time > relative_time(now(), "-24h@h"), mvappend("TP_all", "TP_24h"), "TP_all")
``` chart supports only 2 by fields ```
| eval HI = mvzip(host, index, "::")
| chart count by HI TP
| eval Comparision = if(TP_all = TP_all - TP_24h, "Not Available", "Available")
| mvexpand HI
| eval host = mvindex(split(HI, "::"),0), index = mvindex(split(HI, "::"),1)
| table index host Comparision

r. Ismo 

View solution in original post

isoutamo
SplunkTrust
SplunkTrust

Hi

Here is one example how you could do it

index=* ``` This is not a best practices, try to define used indexes```
| eval TP = if (_time > relative_time(now(), "-24h@h"), mvappend("TP_all", "TP_24h"), "TP_all")
``` chart supports only 2 by fields ```
| eval HI = mvzip(host, index, "::")
| chart count by HI TP
| eval Comparision = if(TP_all = TP_all - TP_24h, "Not Available", "Available")
| mvexpand HI
| eval host = mvindex(split(HI, "::"),0), index = mvindex(split(HI, "::"),1)
| table index host Comparision

r. Ismo 

Mrig342
Contributor

Hi @isoutamo ,

 

Can you please explain me what you did in this below step.

| eval TP = if (_time > relative_time(now(), "-24h@h"), mvappend("TP_all", "TP_24h"), "TP_all")

  

Thank You..!!

0 Karma

isoutamo
SplunkTrust
SplunkTrust

I create a mv field which contains TP_all only or TP_all and TP_24h values if _time is within last 24h. Then when I do chart over it, it calculates it "correctly" for both periods. 

Mrig342
Contributor

Thank you very much @isoutamo ...!!

Your kind inputs are highly appreciated. Cheers..!!

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...