Apply conditional formatting based on a calculated measure

Conditional formatting

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div>
  <h2>Apply conditional formatting based on a calculated measure</h2>
  <p>
    This example shows how to apply conditional formatting based on a
    <a href="https://www.flexmonster.com/doc/calculated-values/" target="_blank"
    >calculated measure</a>. It can be done by specifying the value's
    <a
      href="https://www.flexmonster.com/api/measure-object/#uniquename"
      target="_blank"
    >uniqueName</a> in the <code>formula</code> property.
  </p>
  <p>
    We are formatting the <code>"Price"</code> measure based on the
    <code>"Revenue"</code> calculated measure (lines 17-21 in the JavaSript box).
    Check out how the the <code>formula</code> property is specified (line 26 in
    the JavaScript box).
  </p>
  <p>
    Learn more about
    <a
      href="https://www.flexmonster.com/doc/conditional-formatting/"
      target="_blank"
    >conditional formatting</a> in Flexmonster.
  </p>
</div>

<div id="pivot-container"></div>

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);

JavaScript

const pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  height: 430,
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    slice: {
      rows: [{
        uniqueName: "Category"
      }],
      measures: [{
          uniqueName: "Price"
        },
        {
          uniqueName: "Revenue",
          formula: "sum('Quantity') * sum('Price')",
          individual: true
        }
      ]
    },
    conditions: [{
      measure: "Price",
      formula: "'Revenue' > 50000000",
      format: {
        fontSize: "14px",
        fontWeight: "bold",
        backgroundColor: "#FF79CD", // Pink
        color: "#FFFFFF"
      }
    }]
  }
});