Mark question on Deneb Line Chart

I am hoping someone can help me, deneb NEWBIE but addict.

I have a VERY basic line chart, with text marks for labels. Where do I need to look find out how to show only every third mark (made up 3rd, could be any number). Basically, I just don’t want to have the text mark show up on EVERY point.

Here is my code:

{
“height”: “container”,
“width”:“container”,

“data”: {“name”: “dataset”},

“layer”: [{
“mark”: {
“type”:“line”,
“strokeWidth”: 2,
“interpolate”:“cardinal”,
“tooltip”:true,
“point”: {
“filled”: false,
“fill”: “orange”
}
}
},
{
“mark”:{
“type”: “text”,
“dy”: -15,
“dx”: 0,
“fontSize”:8
},
“encoding”:{
“text”:{
“field”:“transports-MF”
}
}
}
],
“encoding”: {
“y”: {
“field”: “transports-MF”,
“type”:“quantitative”,
“title”:null
},
“x”:{
“field”: “Week Number”,
“type”:“nominal”,
“title”:null
}
}
}

Hi @cwnoll.

There are probably many ways to accomplish this. The first option that occurred to me was to filter the dataset and for the “text” mark to show only the records you want. To that end, I added a “transform” block with a calculation of the remainder (modulus) for each data row. Deneb adds a hidden field to every record of the dataset supplied by Power BI entitled __row__, and this field can be used in calculations. (I included 2 separate “transform” blocks to illustrate the data changes and filtering, but would probably would only use one in a real report.)

(I made-up a small 90-record dataset to illustrate the issue and my solution.)

Here’s the Deneb/Vega-Lite JSON code:

{
  "title": {
    "anchor": "start",
    "align": "left",
    "offset": 20,
    "text": "eDNA Forum - Deneb Nth Data Label",
    "font": "Verdana",
    "fontSize": 24,
    "fontWeight": "bold",
    "fontStyle": "normal"
  },
  "width": 1000,
  "data": { "name": "dataset" },
  "transform": [
    {
      // adjust the modulus divisor as desired
      "calculate": "datum['__row__'] % 3",
      "as": "_nth_row_remainder"
    }
  ],
  "encoding": {
    "x": {
      "field": "ID",
      "type": "quantitative",
      "axis": {
        "labelAngle": 0,
        "tickCount": 20
      }
    },
    "y": {
      "field": "Value",
      "type": "quantitative"
    }
  },
  "layer": [
    {
      "name": "FULL_DATA",
      "mark": {
        "type": "line",
        "opacity": 0.3
      }
    },
    {
      "name": "NTH_DATA_LABEL",
      "transform": [
        {
          "filter": "datum['_nth_row_remainder'] == 0"
        }
      ],
      "mark": {
        "type": "text",
        "align": "left",
        "xOffset": 3
      },
      "encoding": {
        "text": {
          "field": "Value",
          "type": "quantitative",
          "format": ".4f"
        }
      }
    }
  ]
}

Hope it helps.
Greg
eDNA Forum - Deneb Nth Data Label.pbix (2.3 MB)
Random.xlsx (13.3 KB)

thank you, Greg, so much this will for sure point me in the right direction. Great resource.