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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Jared__
Frequent Visitor

Deneb, Vega - Lite (Meeko chart)

Hi, 

Pure begginer here on vega-lite code. I have a code written by Daniel , one of the creators of Deneb. I'm trying to replicate the code by adding my own measures such as "Sales Volume", "Gross Profit" and "Region" instead of "No of Responses" , "NPS Score" & "Location".

I've tried replacing the values to fit my new measures. But what i've noticed is that the chart turns blank. and shows no values..

Hope someone can bring some light to this..

 

{
  "data": {"name": "dataset"},
  "transform": [
    {
      "stack": "No of Responses",
      "sort": [
        {
          "field": "NPS Score",
          "order": "descending"
        }
      ],
      "as": ["v1", "v2"],
      "groupby": []
    },
    {
      "calculate": "datum['v2'] - ((datum['v2'] - datum['v1']) / 2)",
      "as": "category_mid"
    }
  ],
  "encoding": {
    "x": {
      "type": "quantitative",
      "axis": null
    },
    "y": {
      "type": "quantitative",
      "axis": {"title": null},
      "scale": {
        "domain": [-100, 100],
        "range": [
          {"expr": "height - 40"},
          0
        ]
      }
    },
    "tooltip": [
      {
        "field": "Location",
        "type": "nominal"
      },
      {
        "field": "NPS Score",
        "type": "quantitative",
        "formatType": "pbiFormat",
        "format": "#"
      },
      {
        "field": "No of Responses",
        "type": "quantitative"
      }
    ]
  },
  "layer": [
    {
      "mark": {
        "type": "bar",
        "tooltip": true
      },
      "encoding": {
        "x": {"field": "v1"},
        "x2": {"field": "v2"},
        "y": {"field": "NPS Score"},
        "y2": {"datum": 0},
        "color": {
          "condition": [
            {
              "test": "datum['NPS Score'] <= 0",
              "value": "#FF4400"
            }
          ],
          "value": "#3AD11F"
        }
      }
    },
    {
      "mark": {"type": "text", "baseline": "bottom"},
      "encoding": {
        "x": {"field": "category_mid"},
        "y": {"value": {"expr": "height - 15"}},
        "text": {"field": "Location"}
      }
    },
    {
      "mark": {"type": "text", "baseline": "bottom"},
      "encoding": {
        "x": {"field": "category_mid"},
        "y": {"value": "height"},
        "text": {"field": "No of Responses"}
      }
    },
    {
      "transform": [
        {
          "calculate": "datum['NPS Score'] / 2",
          "as": "y_midpoint"
        }
      ],
      "mark": {
        "type": "text",
        "color": "black"
      },
      "encoding": {
        "text": {
          "field": "NPS Score",
          "formatType": "pbiFormat",
          "format": "#"
        },
        "x": {"field": "category_mid"},
        "y": {"field": "y_midpoint"}
      }
    }
  ]
}

 

 BR

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @Jared__ ,

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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