Dashboards & Visualizations

Why doesn't this if statement work for field coloring?

tkwaller1
Path Finder

I have an if statement in my dashboard code but it doesnt work and I have no idea why. Heres the code:

 

 

<row>
    <panel>
      <title>Submission Details</title>
      <table>
        <search>
          <query>index=my_db sourcetype="my:details"
| fillnull value="NA"  ID INT_MESSAGE_ID APPLICATION_NUMBER APPLICATION_TYPE SUBMISSION_NUMBER SUBMISSION_TYPE SUPPORTING_DOC_NUMBER GLOBAL_ID DUNS FEI PROJECT_ID MESSAGE_STATUS MESSAGE_COMMENT LAST_UPDATE_TIMESTAMP 
| stats count by ID INT_MESSAGE_ID APPLICATION_NUMBER APPLICATION_TYPE SUBMISSION_NUMBER SUBMISSION_TYPE SUPPORTING_DOC_NUMBER GLOBAL_ID DUNS FEI PROJECT_ID MESSAGE_STATUS MESSAGE_COMMENT LAST_UPDATE_TIMESTAMP 
| fields - count
| sort -INT_MESSAGE_ID</query>
          <earliest>$field1.earliest$</earliest>
          <latest>$field1.latest$</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">10</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="refresh.display">progressbar</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">false</option>
        <option name="wrap">true</option>
        <format type="color" field="MESSAGE_STATUS">
          <colorPalette type="expression">if (MESSAGE_COMMENT == "Processed", "#53A051", "#DC4E41")</colorPalette>
        </format>
      </table>
    </panel>
  </row>

 

 

 

 

Labels (4)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

Yes. As I said, you can only refer to the value of the cell using the "value" argument. So you could use

if (value=="something", "#000000","#ffffff")

But that's not what you want because this colours a cell based on this cell's value, not other column.

Unfortunately the only way to do so is using external JS and CSS.

You can see how it's done in Dashboard Examples app https://splunkbase.splunk.com/app/1603

View solution in original post

0 Karma

PickleRick
SplunkTrust
SplunkTrust

I don't think you can simply colour one column's cell based on another column value with expression. With the expression color palette type you can only reference value of the cell you're colouring.

0 Karma

tkwaller1
Path Finder

I tried this just to test, 

<format type="color" field="MESSAGE_COMMENT">
          <colorPalette type="expression">if (MESSAGE_COMMENT="Processed","#53A051","#DC4E41") </colorPalette>
        </format>

 

It only colors the else portion. Like nothing meets the first condition. Even though 80% of my records are "Processed"

0 Karma

PickleRick
SplunkTrust
SplunkTrust

Yes. As I said, you can only refer to the value of the cell using the "value" argument. So you could use

if (value=="something", "#000000","#ffffff")

But that's not what you want because this colours a cell based on this cell's value, not other column.

Unfortunately the only way to do so is using external JS and CSS.

You can see how it's done in Dashboard Examples app https://splunkbase.splunk.com/app/1603

0 Karma

tkwaller1
Path Finder

Thanks,  sorry for not understanding hahaha. I follow now.

Thats exactly what I was looking for. It works now.

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: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

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

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