Dashboards & Visualizations

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

tkwaller1
Engager

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
Ultra Champion

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
Ultra Champion

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
Engager

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
Ultra Champion

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
Engager

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

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

0 Karma
Get Updates on the Splunk Community!

Customer Experience | Join the Customer Advisory Board!

Are you ready to take your Splunk journey to the next level? &#x1f680; We invite you to join our elite squad ...

Observability Cloud | AWS PrivateLink Enabled for Splunk Observability Cloud

We’ve enabled AWS PrivateLink for Observability Cloud, giving you an additional inbound connection to send ...

Index This | A sphere has three, a circle has two, and a point has zero. What is it?

September 2023 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...