B, try the below for a horizontal visualization. It changes from black to red based on variance.
{
“title”:{
“orient”: “top”,
“offset”: -1,
“text”: “Units Sold”,
“font”: “Segoe UI”,
“fontSize”: 16,
“fontWeight”: “normal”,
“fontStyle”: “normal”
},
“data”: {“name”: “dataset”},
“transform”: [
{
“calculate”: “datum[‘Actual’] - datum[‘Prior Year’]”,
“as”: “PY Variance”
},
{
“calculate”: “datum[‘PY Variance’] / datum[‘Prior Year’]”,
“as”: “PY % Var”
},
{
“calculate”: “datum[‘Actual’] - datum[‘Budget’]”,
“as”: “Budget Variance”
},
{
“calculate”: “datum[‘Budget Variance’] / datum[‘Budget’]”,
“as”: “Budget % Var”
},
{
“calculate”: “datum[‘Actual’] - datum[‘Stretch1’]”,
“as”: “Stretch1 Variance”
}
],
“encoding”: {
“x”: {
“type”: “quantitative”,
“scale”: {“nice”: false},
“title”: null,
“axis”: null
}
},
“layer”: [
{
“description”: “PRIOR YEAR BAR”,
“mark”: {
“type”: “bar”,
“color”: {“expr”: “pbiColor(0,0.7)”},
“size”: 30,
“yOffset”: 7,
“tooltip”: true
},
“encoding”: {
“x”: {“field”: “Prior Year”},
“y”: {
“field”: “”,
“axis”: null
},
“tooltip”: [
{
“field”: “Actual”,
“type”: “quantitative”,
“formatType”: “pbiFormat”,
“format”: “#,#”
},
{
“field”: “Prior Year”,
“type”: “quantitative”,
“formatType”: “pbiFormat”,
“format”: “#,#”
},
{
“field”: “PY Variance”,
“title”: “+/-:”,
“type”: “quantitative”,
“formatType”: “pbiFormat”,
“format”: “#,#”
},
{
“field”: “PY % Var”,
“title”: “%:”,
“type”: “quantitative”,
“formatType”: “pbiFormat”,
“format”: “#%”
}]
}
},
{
"description": "ACTUAL YEAR BAR",
"mark": {
"type": "bar",
"size": 18,
"color": {"expr": "datum ['Actual'] < datum ['Prior Year'] ? 'red':'black' "},
"yOffset": 5,
"tooltip": true
},
"encoding": {
"x": {"field": "Actual"},
"y": {
"field": "",
"axis": null
},
"tooltip": [
{
"field": "Actual",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#,#"
},
{
"field": "Prior Year",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#,#"
},
{
"field": "PY Variance",
"title": "+/-:",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#,#"
},
{
"field": "PY % Var",
"title": "%:",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#%"
}]
}
},
{
"description": "ACTUAL YEAR TEXT",
"mark": {
"type": "text",
"dx": 0,
"dy": 0,
"xOffset": -2,
"yOffset": 14,
"angle": 0,
"align": "right",
"baseline": "bottom",
"font": "sans-serif",
"fontSize": 16,
"fontStyle": "normal",
"fontWeight": "normal",
"color": "white",
"tooltip": "true",
"limit": 0
},
"encoding": {
"x": {
"aggregate": "max",
"field": "Actual",
"type": "quantitative"
},
"text": {
"field": "Actual",
"format": ".2s"
}
,
"tooltip": [
{
"field": "Actual",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#,#"
},
{
"field": "Prior Year",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#,#"
},
{
"field": "PY Variance",
"title": "+/-:",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#,#"
},
{
"field": "PY % Var",
"title": "%:",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#%"
}]
}
},
{
"description": "VARIANCE TEXT",
"mark": {
"type": "text",
"color": {"expr": "datum ['Actual'] < datum ['Prior Year'] ? 'red':'black' "},
"dx": 0,
"dy": 0,
"xOffset": 0,
"yOffset": -18,
"angle": 0,
"align": "center",
"baseline": "top",
"font": "sans-serif",
"fontSize": 10,
"fontStyle": "normal",
"fontWeight": "normal",
"limit": 0
},
"encoding": {
"x": {
"aggregate": "max",
"type": "quantitative"
},
"text": {
"field": "PY % Var",
"title": "%:",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#% vs PY"
}
,
"tooltip": [
{
"field": "Actual",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#,#"
},
{
"field": "Prior Year",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#,#"
},
{
"field": "PY Variance",
"title": "+/-:",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#,#"
},
{
"field": "PY % Var",
"title": "%:",
"type": "quantitative",
"formatType": "pbiFormat",
"format": "#%"
}]
}
}
]
}