Forum Discussion
majid154a
6 months agoHelper II
waterfall by deneb
Hello, The community helped me create a waterfall chart using DAX at the following link: https://community.fabric.microsoft.com/t5/Desktop/Waterfall-Challenge/m-p/4942137#M1456881 The data I’m usi...
majid154a
6 months agoHelper II
Thank you Olufemi7
can yuu put this changes in the code below, becuase there is no background from my side:
{
"data": { "name": "dataset" },
"transform": [
{
"calculate": "datum['Cat Short'] == 'Budget' ? 'Budget' : datum['Cat Short'] == 'Actual NPAT' ? 'Total' : datum.value >= 0 ? 'Increase' : 'Decrease'",
"as": "Type"
},
{
"calculate": "datum['Cat Short'] == 'Budget' || datum['Cat Short'] == 'Actual NPAT' ? 0 : datum['WF Start']",
"as": "WF_Start_Adjusted"
},
{
"calculate": "datum['WF End']",
"as": "WF_End_Adjusted"
}
],
"layer": [
{
"mark": { "type": "bar" },
"encoding": {
"x": {
"field": "Cat Short",
"type": "ordinal",
"sort": { "field": "index" },
"axis": { "title": null, "labelAngle": 0, "labelFontSize": 11, "labelPadding": 10 },
"scale": { "padding": 0.4 }
},
"y": {
"field": "WF_Start_Adjusted",
"type": "quantitative",
"axis": { "title": null, "grid": false, "labels": false, "ticks": false }
},
"y2": { "field": "WF_End_Adjusted" },
"color": {
"field": "Type",
"type": "nominal",
"scale": { "domain": ["Budget", "Increase", "Decrease", "Total"], "range": ["#808080", "#00B050", "#C00000", "#0070C0"] },
"legend": null
},
"tooltip": [
{ "field": "cat", "type": "nominal", "title": "Category" },
{ "field": "value", "type": "quantitative", "title": "Amount", "format": ",.0f" },
{ "field": "WF Start", "type": "quantitative", "format": ",.0f" },
{ "field": "WF End", "type": "quantitative", "format": ",.0f" }
]
}
},
{
"mark": { "type": "text", "fontSize": 11, "fontWeight": "bold", "dy": -12 },
"encoding": {
"x": { "field": "Cat Short", "type": "ordinal", "sort": { "field": "index" } },
"y": { "field": "WF_End_Adjusted", "type": "quantitative" },
"text": { "field": "value", "type": "quantitative", "format": ",.0f" },
"color": { "value": "black" }
}
}
]
}
Olufemi7
6 months agoSuper User
Hi majid154a,
Thank you for sharing your full spec.
Below is your corrected version with the changes applied directly to your existing structure.
✔ What’s updated
Actual NPAT starts from zero
Actual NPAT color = #A4D233
Budget color = #389BBD
Labels remain above bars
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": { "name": "dataset" },
"transform": [
{
"calculate": "datum['Cat Short'] == 'Budget' ? 'Budget' : datum['Cat Short'] == 'Actual NPAT' ? 'Total' : datum.value >= 0 ? 'Increase' : 'Decrease'",
"as": "Type"
},
{
"calculate": "datum['Cat Short'] == 'Actual NPAT' ? 0 : datum['WF Start']",
"as": "WF_Start_Adjusted"
},
{
"calculate": "datum['WF End']",
"as": "WF_End_Adjusted"
}
],
"layer": [
{
"mark": { "type": "bar" },
"encoding": {
"x": {
"field": "Cat Short",
"type": "ordinal",
"sort": { "field": "index" },
"axis": { "title": null, "labelAngle": 0, "labelFontSize": 11, "labelPadding": 10 },
"scale": { "padding": 0.4 }
},
"y": {
"field": "WF_Start_Adjusted",
"type": "quantitative",
"axis": { "title": null, "grid": false, "labels": false, "ticks": false }
},
"y2": { "field": "WF_End_Adjusted" },
"color": {
"condition": [
{
"test": "datum['Cat Short'] == 'Actual NPAT'",
"value": "#A4D233"
},
{
"test": "datum['Cat Short'] == 'Budget'",
"value": "#389BBD"
}
],
"field": "Type",
"type": "nominal",
"scale": {
"domain": ["Increase", "Decrease", "Total"],
"range": ["#00B050", "#C00000", "#808080"]
},
"legend": null
},
"tooltip": [
{ "field": "cat", "type": "nominal", "title": "Category" },
{ "field": "value", "type": "quantitative", "title": "Amount", "format": ",.0f" },
{ "field": "WF Start", "type": "quantitative", "format": ",.0f" },
{ "field": "WF End", "type": "quantitative", "format": ",.0f" }
]
}
},
{
"mark": {
"type": "text",
"fontSize": 11,
"fontWeight": "bold",
"dy": -12
},
"encoding": {
"x": {
"field": "Cat Short",
"type": "ordinal",
"sort": { "field": "index" }
},
"y": {
"field": "WF_End_Adjusted",
"type": "quantitative"
},
"text": {
"field": "value",
"type": "quantitative",
"format": ",.0f"
},
"color": { "value": "black" }
}
}
]
}
If needed, you can slightly increase dy (e.g., -14) to move labels higher.
This version aligns fully with your existing field names and should work correctly in Deneb