Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Doug7983
Helper I
Helper I

Deneb heatmap color tweak

Apologies but workplace security policies and practices prevent me from uploading a pbix, etc.

I have a Deneb spec that I am reusing that, thanks to earlier contributions from @giammariam , is almost exactly what I need:

Example1.png


Until it's filtered (using a slicer) and an extreme outlier (in dark blue) dominates the color scale:

ex2.png
Stakeholders are asking whether each row --across the fiscal years--can be colored independently. In other words, every row would have its own "blueorange" scale (in reverse). I have tried many approaches that have not worked. Here is my spec. Thanks for any help offered.

{
  "transform": [
    {
      "calculate": "(month(datum['Date'])+1)",
      "as": "monthNum"
    },
    {
      "calculate": "datum['monthNum'] + (datum['monthNum'] < 7 ? 6 : -6)",
      "as": "monthSort"
    },
    {
      "calculate": "'FY ' + toString(year(datum['Date']) + (datum['monthSort'] <= 6 ? +1 : 0))",
      "as": "FY"
    }
  ],
  "facet": {
    "column": {
      "field": "FY",
      "title": null,
      "header": {"labelFontSize": 13}
    }
  },
  "resolve": {
    "scale": {"x": "independent"}
  },
  "spacing": {"column": 5},
  "spec": {
    "width": {"step": 35},
    "mark": {
      "type": "rect",
      "stroke": "white",
      "tooltip": true
    },
    "encoding": {
      "x": {
        "field": "Date",
        "type": "ordinal",
        "title": null,
        "timeUnit": "month",
        "axis": {
          "domain": false,
          "ticks": false,
          "labels": true,
          "labelOpacity": 0.65,
          "orient": "top"
        },
        "sort": {"field": "monthSort"}
      },
      "y": {
        "field": "Category",
        "type": "nominal",
        "title": "",
        "axis": {
          "domain": false,
          "ticks": false,
          "labels": true,
          "labelOpacity": 0.65,
          "labelAngle": 0,
          "labelPadding": 5
        }
      },
      "tooltip": [
        {
          "field": "Category",
          "type": "nominal"
        },
        {
          "field": "Date ",
          "type": "nominal"
        },
        {
          "field": "Metric",
          "type": "quantitative",
          "format": ".1%"
        }
      ],
      "color": {
        "aggregate": "max",
        "field": "Metric",
        "type": "quantitative",
        "title": "Metric",
        "scale": {
          "reverse": true,
          "scheme": "blueorange"
        },
        "legend": {
          "title": "",
          "titleAnchor": "middle",
          "titleBaseline": "top",
          "direction": "horizontal",
          "format": "%",
          "orient": "bottom-right",
          "offset": 14
        }
      }
    }
  },
  "data": {"name": "dataset"}
}





13 REPLIES 13
KerKol
Super User
Super User

Adding on to @giammariam, I believe I've done something similar too Independent Scales with Deneb (Ring Chart) - EXPLORATIONS IN DATA STORYTELLING WITH POWER BI (kerryk...





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks for the reply, @KerKol. My experience with Deneb is limited, so it's likely I didn't pick the right piece or pieces from your spec.

I adpated this piece of your spec for my visual:

"color": {
          "field": "__4__",
          "type": "quantitative",
          "title": "Marriages",
          "scale": {
            "range": [
              "transparent",
              "#de9ed6"

Other than the color scheme, the only difference now was that a rectangle with an underlying value of -17% looks not to be colored. 

example.png


giammariam
Super User
Super User

Hey @Doug7983. Try something like the following. Note - I left comments to show what I updated from my original solution (you'll want to remove comments before migrating to Deneb).

Before:

giammariam_2-1710594404339.png
After:

giammariam_0-1710594290931.png


Here's the spec in the Vega Editor.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "transform": [
    {"calculate": "(month(datum['Date'])+1)", "as": "monthNum"},
    {
      "calculate": "datum['monthNum'] + (datum['monthNum'] < 7 ? 6 : -6)",
      "as": "monthSort"
    },
    {
      "calculate": "'FY ' + toString(year(datum['Date']) + (datum['monthSort'] <= 6 ? +1 : 0))",
      "as": "FY"
    },
    /*** transform addition start ***/
    {
      "calculate": "datum['Growth (WDC)'] < 0 ? -1 : datum['Growth (WDC)'] === 0 ? 0 : 1",
      "as": "Sign"
    },
    {
      "joinaggregate": [
        {
          "op": "count",
          "field": "Growth (WDC)",
          "as": "Sign Count"
        },
        {
          "op": "max",
          "field": "Growth (WDC)",
          "as": "Max Growth (WDC)"
        }
      ],
      "groupby": ["Category", "Sign"]
    },
    {
      "calculate": "datum['Sign'] === 0 ? 0 : datum['Sign'] > 0 ? datum['Growth (WDC)']/datum['Max Growth (WDC)'] : -(datum['Growth (WDC)']/datum['Max Growth (WDC)'])",
      "as": "Relative Growth %"
    }
    /*** transform addition end ***/
  ],
  "facet": {
    "column": {"field": "FY", "title": null, "header": {"labelFontSize": 13}}
  },
  "resolve": {"scale": {"x": "independent"}},
  "spacing": {"column": 5},
  "spec": {
    "width": {"step": 30},
    "mark": {"type": "rect", "stroke": "white", "tooltip": true},
    "encoding": {
      "x": {
        "field": "Date",
        "type": "ordinal",
        "title": null,
        "timeUnit": "month",
        "axis": {
          "domain": false,
          "ticks": false,
          "labels": true,
          "labelOpacity": 0.65,
          "orient": "top"
        },
        "sort": {"field": "monthSort"}
      },
      "y": {
        "field": "Category",
        "type": "nominal",
        "title": "",
        "axis": {
          "domain": false,
          "ticks": false,
          "labels": true,
          "labelOpacity": 0.65,
          "labelAngle": 0,
          "labelPadding": 5
        }
      },
      "tooltip": [
        {"field": "Category", "type": "nominal"},
        {"field": "Date", "type": "temporal"},
        {"field": "Growth (MoYaM)", "type": "quantitative", "format": ".1%"},
        {"field": "Growth (WDC)", "type": "quantitative", "format": ".1%"}
      ],
      /*** color encoding update start ***/
      "color": {
        "aggregate": "max",
        "field": "Relative Growth %",
        "type": "quantitative",
        "title":  ["Relative Growth (WDC)", "by Category"],
        "scale": {"domainMid": 0, "domainMin": -1, "domainMax": 1, "reverse": true, "scheme": "blueorange"},
        "legend": {
          "titleBaseline": "bottom",
          "direction": "horizontal",
          "format": ".1%",
          "orient": "right"
        }
      }
      /*** color encoding update end ***/
    }
  },
  "data": {
    "name": "dataset",
    "values": [
      {
        "Date": "11/1/2021",
        "Category": "Category 01",
        "Growth (WDC)": "0.23",
        "Growth (MoYaM)": "0.30"
      },
      {
        "Date": "12/1/2021",
        "Category": "Category 01",
        "Growth (WDC)": "0.12",
        "Growth (MoYaM)": "0.12"
      },
      {
        "Date": "1/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.13",
        "Growth (MoYaM)": "0.19"
      },
      {
        "Date": "2/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.09",
        "Growth (MoYaM)": "0.09"
      },
      {
        "Date": "3/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.21",
        "Growth (MoYaM)": "0.21"
      },
      {
        "Date": "4/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.29",
        "Growth (MoYaM)": "0.24"
      },
      {
        "Date": "5/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.36",
        "Growth (MoYaM)": "0.43"
      },
      {
        "Date": "6/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.28",
        "Growth (MoYaM)": "0.28"
      },
      {
        "Date": "7/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.42",
        "Growth (MoYaM)": "0.14"
      },
      {
        "Date": "8/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.28",
        "Growth (MoYaM)": "0.34"
      },
      {
        "Date": "9/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.18",
        "Growth (MoYaM)": "0.24"
      },
      {
        "Date": "10/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.19",
        "Growth (MoYaM)": "0.19"
      },
      {
        "Date": "11/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.09",
        "Growth (MoYaM)": "0.09"
      },
      {
        "Date": "12/1/2022",
        "Category": "Category 01",
        "Growth (WDC)": "0.14",
        "Growth (MoYaM)": "0.14"
      },
      {
        "Date": "1/1/2023",
        "Category": "Category 01",
        "Growth (WDC)": "0.10",
        "Growth (MoYaM)": "0.10"
      },
      {
        "Date": "2/1/2023",
        "Category": "Category 01",
        "Growth (WDC)": "0.09",
        "Growth (MoYaM)": "0.09"
      },
      {
        "Date": "3/1/2023",
        "Category": "Category 01",
        "Growth (WDC)": "0.13",
        "Growth (MoYaM)": "0.13"
      },
      {
        "Date": "4/1/2023",
        "Category": "Category 01",
        "Growth (WDC)": "0.06",
        "Growth (MoYaM)": "0.01"
      },
      {
        "Date": "5/1/2023",
        "Category": "Category 01",
        "Growth (WDC)": "0.03",
        "Growth (MoYaM)": "0.13"
      },
      {
        "Date": "6/1/2023",
        "Category": "Category 01",
        "Growth (WDC)": "0.07",
        "Growth (MoYaM)": "0.07"
      },
      {
        "Date": "7/1/2023",
        "Category": "Category 01",
        "Growth (WDC)": "0.12",
        "Growth (MoYaM)": "0.12"
      },
      {
        "Date": "8/1/2023",
        "Category": "Category 01",
        "Growth (WDC)": "0.14",
        "Growth (MoYaM)": "0.14"
      },
      {
        "Date": "9/1/2023",
        "Category": "Category 01",
        "Growth (WDC)": "0.18",
        "Growth (MoYaM)": "0.12"
      },
      {
        "Date": "10/1/2023",
        "Category": "Category 01",
        "Growth (WDC)": "0.15",
        "Growth (MoYaM)": "-0.62"
      },
      {
        "Date": "11/1/2021",
        "Category": "Category 03",
        "Growth (WDC)": "0.15",
        "Growth (MoYaM)": "0.21"
      },
      {
        "Date": "12/1/2021",
        "Category": "Category 03",
        "Growth (WDC)": "0.11",
        "Growth (MoYaM)": "0.11"
      },
      {
        "Date": "1/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.14",
        "Growth (MoYaM)": "0.20"
      },
      {
        "Date": "2/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.12",
        "Growth (MoYaM)": "0.12"
      },
      {
        "Date": "3/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.12",
        "Growth (MoYaM)": "0.12"
      },
      {
        "Date": "4/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.14",
        "Growth (MoYaM)": "0.08"
      },
      {
        "Date": "5/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.16",
        "Growth (MoYaM)": "0.22"
      },
      {
        "Date": "6/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.07",
        "Growth (MoYaM)": "0.07"
      },
      {
        "Date": "7/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.18",
        "Growth (MoYaM)": "-0.06"
      },
      {
        "Date": "8/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.08",
        "Growth (MoYaM)": "0.13"
      },
      {
        "Date": "9/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "-0.02",
        "Growth (MoYaM)": "0.03"
      },
      {
        "Date": "10/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.08",
        "Growth (MoYaM)": "0.08"
      },
      {
        "Date": "11/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.12",
        "Growth (MoYaM)": "0.12"
      },
      {
        "Date": "12/1/2022",
        "Category": "Category 03",
        "Growth (WDC)": "0.07",
        "Growth (MoYaM)": "0.07"
      },
      {
        "Date": "1/1/2023",
        "Category": "Category 03",
        "Growth (WDC)": "0.04",
        "Growth (MoYaM)": "0.04"
      },
      {
        "Date": "2/1/2023",
        "Category": "Category 03",
        "Growth (WDC)": "0.08",
        "Growth (MoYaM)": "0.08"
      },
      {
        "Date": "3/1/2023",
        "Category": "Category 03",
        "Growth (WDC)": "0.19",
        "Growth (MoYaM)": "0.19"
      },
      {
        "Date": "4/1/2023",
        "Category": "Category 03",
        "Growth (WDC)": "0.14",
        "Growth (MoYaM)": "0.09"
      },
      {
        "Date": "5/1/2023",
        "Category": "Category 03",
        "Growth (WDC)": "0.05",
        "Growth (MoYaM)": "0.16"
      },
      {
        "Date": "6/1/2023",
        "Category": "Category 03",
        "Growth (WDC)": "0.13",
        "Growth (MoYaM)": "0.13"
      },
      {
        "Date": "7/1/2023",
        "Category": "Category 03",
        "Growth (WDC)": "0.09",
        "Growth (MoYaM)": "0.09"
      },
      {
        "Date": "8/1/2023",
        "Category": "Category 03",
        "Growth (WDC)": "0.11",
        "Growth (MoYaM)": "0.11"
      },
      {
        "Date": "9/1/2023",
        "Category": "Category 03",
        "Growth (WDC)": "0.06",
        "Growth (MoYaM)": "0.01"
      },
      {
        "Date": "10/1/2023",
        "Category": "Category 03",
        "Growth (WDC)": "0.02",
        "Growth (MoYaM)": "-0.66"
      },
      {
        "Date": "11/1/2021",
        "Category": "Category 10",
        "Growth (WDC)": "0.24",
        "Growth (MoYaM)": "0.31"
      },
      {
        "Date": "12/1/2021",
        "Category": "Category 10",
        "Growth (WDC)": "0.16",
        "Growth (MoYaM)": "0.16"
      },
      {
        "Date": "1/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.12",
        "Growth (MoYaM)": "0.18"
      },
      {
        "Date": "2/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.11",
        "Growth (MoYaM)": "0.11"
      },
      {
        "Date": "3/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.18",
        "Growth (MoYaM)": "0.18"
      },
      {
        "Date": "4/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.22",
        "Growth (MoYaM)": "0.16"
      },
      {
        "Date": "5/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.15",
        "Growth (MoYaM)": "0.21"
      },
      {
        "Date": "6/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.13",
        "Growth (MoYaM)": "0.13"
      },
      {
        "Date": "7/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.25",
        "Growth (MoYaM)": "0.00"
      },
      {
        "Date": "8/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.09",
        "Growth (MoYaM)": "0.14"
      },
      {
        "Date": "9/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.09",
        "Growth (MoYaM)": "0.14"
      },
      {
        "Date": "10/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.13",
        "Growth (MoYaM)": "0.13"
      },
      {
        "Date": "11/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.03",
        "Growth (MoYaM)": "0.03"
      },
      {
        "Date": "12/1/2022",
        "Category": "Category 10",
        "Growth (WDC)": "0.01",
        "Growth (MoYaM)": "0.01"
      },
      {
        "Date": "1/1/2023",
        "Category": "Category 10",
        "Growth (WDC)": "0.04",
        "Growth (MoYaM)": "0.04"
      },
      {
        "Date": "2/1/2023",
        "Category": "Category 10",
        "Growth (WDC)": "0.00",
        "Growth (MoYaM)": "0.00"
      },
      {
        "Date": "3/1/2023",
        "Category": "Category 10",
        "Growth (WDC)": "-0.08",
        "Growth (MoYaM)": "-0.08"
      },
      {
        "Date": "4/1/2023",
        "Category": "Category 10",
        "Growth (WDC)": "-0.08",
        "Growth (MoYaM)": "-0.12"
      },
      {
        "Date": "5/1/2023",
        "Category": "Category 10",
        "Growth (WDC)": "-0.05",
        "Growth (MoYaM)": "0.05"
      },
      {
        "Date": "6/1/2023",
        "Category": "Category 10",
        "Growth (WDC)": "-0.06",
        "Growth (MoYaM)": "-0.06"
      },
      {
        "Date": "7/1/2023",
        "Category": "Category 10",
        "Growth (WDC)": "-0.03",
        "Growth (MoYaM)": "-0.03"
      },
      {
        "Date": "8/1/2023",
        "Category": "Category 10",
        "Growth (WDC)": "0.00",
        "Growth (MoYaM)": "0.00"
      },
      {
        "Date": "9/1/2023",
        "Category": "Category 10",
        "Growth (WDC)": "-0.02",
        "Growth (MoYaM)": "-0.06"
      },
      {
        "Date": "10/1/2023",
        "Category": "Category 10",
        "Growth (WDC)": "-0.07",
        "Growth (MoYaM)": "-0.69"
      }
    ]
  }
}



Let me know if this gets you what you're after.



Madison Giammaria
Proud to be a Super User 😄
LinkedIn

Do you frequently use Deneb to provide insights to your stakeholders? Have you considered sponsoring this free and open source custom visual? More info here!

Thanks for the reply @giammariam . As a start, I simply inserted your transform addition block and clicked apply--just to see what would happen. I was surprised--and puzzled, frankly--that nothing happened. (I thought the visual would break because the field references in the transform addition block are different from what I'm using in this visual, a "Growth" field that has been pre-calculated in DAX.)

@Doug7983, there are also additional changes further down for the color encoding. This example is the same one that you used as an example to to build your current spec using your actual data. The transforms and color encoding updates are the only changes. If you update the field names, the color scale domain and range should now be specific to each category.



Madison Giammaria
Proud to be a Super User 😄
LinkedIn

Do you frequently use Deneb to provide insights to your stakeholders? Have you considered sponsoring this free and open source custom visual? More info here!

@giammariam I really appreciate your efforts, this time and previous times you've helped. I think maybe the spec you're working from is off from the one I'm using just enough to make difficult/confusing for me to implement? I'm not sure. Anyway, when I tried this suggestion, everything broke. 
I'm not sure if it matters, for instance, but my spec has none of the value block that your's does:

  "values": [
      {
        "Date": "11/1/2021",
        "Category": "Category 01",
        "Growth (WDC)": "0.23",
        "Growth (MoYaM)": "0.30"
      },
      {
        "Date": "12/1/2021",
        "Category": "Category 01",
        "Growth (WDC)": "0.12",
        "Growth (MoYaM)": "0.12"
      },

<snipped>

lbendlin
Super User
Super User

I wouldn't know how to do that in Deneb but I have done similar things with the cheapo matrix visual version.  Is that an option for you?

Possibly. The out-of-the-box matrix isn't as space-efficient, though. 

got some sample data?

Thanks for the response, @lbendlin. Here is some sample data:

CategoryDateChange
Category 19/1/202226%
Category 110/1/202235%
Category 111/1/202225%
Category 112/1/202230%
Category 11/1/202322%
Category 12/1/202332%
Category 13/1/202348%
Category 14/1/202335%
Category 15/1/202336%
Category 16/1/202334%
Category 17/1/202328%
Category 18/1/202324%
Category 19/1/202316%
Category 110/1/202344%
Category 111/1/202332%
Category 112/1/202331%
Category 11/1/202434%
Category 12/1/2024215%
Category 13/1/202429%
Category 29/1/202227%
Category 210/1/202223%
Category 211/1/202226%
Category 212/1/202226%
Category 21/1/202329%
Category 22/1/202323%
Category 23/1/202315%
Category 24/1/202321%
Category 25/1/202326%
Category 26/1/2023-17%
Category 27/1/202330%
Category 28/1/202327%
Category 29/1/202326%
Category 210/1/202329%
Category 211/1/202325%
Category 212/1/202324%
Category 21/1/202422%
Category 22/1/202424%
Category 23/1/202416%

Here's how the matrix would look like based on your sample data.

 

lbendlin_2-1710772561255.png

 

 

 

Thanks, @lbendlin . This could possibly work, although my stakeholders are used to seeing the Deneb version and change is hard. I can't get the DAX to work, though. Maybe because "Change" in my data set is a DAX expression and not a column?

Please provide sample data that fully covers your issue.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.