Search code examples
powerbivega-litevegapowerbi-custom-visualsdeneb

How to access the value of a single datum in a dataset using an expression in Vega Lite


We are attempting to parameterize the y-axis domain range by allowing the user to create simple measures (y_min=0.3, y_max=0.7) in PowerBI, and then access these measures within the Vega-lite JSON code to set these scales.

I am able to set the raw values in the JSON, but want to grab the value of the measure in Deneb and assign it to a parameter. Is this possible?


Solution

  • You can upload a .pbix to an external site and link here. However, in answer to your question, the measure needs to be added to the data table supplied to Deneb. When creating a new Deneb visual, a good rule of thumb is to create a table of all the values that will be passed to Deneb before converting the table visual to a Deneb visual. If the measure is part of that original table visual, then it can be extracted and used in your spec.

    EDIT In this example, I have create a param with an expression to get the first row and then symbol value of "GOOG" and called my param d. You should be able to do the same using the correctly named dataset and column name. You don't need a param and can just use an expression but I don't know for sure as you haven't said whether this is Vega or VL.

    {
      "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
      "data": {"url": "data/stocks.csv"},
      "transform": [{"filter": "datum.symbol==='GOOG'"}],
      "params": [{
        "name": "d",
        "expr": "data('source_0')[0].symbol"
      }],
      "mark": "line",
      "encoding": {
        "x": {"field": "date", "type": "temporal"},
        "y": {"field": "price", "type": "quantitative"}
      }
    }
    

    enter image description here