Dyota's blog

Power BI: Line graph, with data label only at the end

Sometimes, you only care about what the most recent number is on a line graph. I wanted to have line graphs with a data label, but only at the end.

Turning on data labels for everything tends to graphically clutter things up, and sometimes it's not visually affordable to have people read off values from the Y-axis.

Most importantly, I wanted to do this with Power BI out of the box. I didn't want to have to go to a third party visual, or learn to hack one together with Deneb or something.

I achieved this by writing a measure for each data label that I wanted to see. See the finished result here.

The "actuals" data label and the "budget" data label had on measure each. The trick was to only calculate it if the date was the latest one.

Actual Most Recent = 
VAR latestDate = CALCULATE(
    MAX(datatable[Snapshot Date]),
    ALLSELECTED(datatable)
)
VAR out = CALCULATE(
    SUMX(
        datatable, 
        datatable[Actuals]
    ),
    FILTER(
        datatable, 
        [Snapshot Date] = latestDate
    )
)
RETURN out
Budget Most Recent = 
VAR latestDate = CALCULATE(
    MAX(datatable[Snapshot Date]),
    ALLSELECTED(datatable)
)
VAR out = CALCULATE(
    SUMX(
        datatable, 
        datatable[Budget]
    ),
    FILTER(
        datatable, 
        [Snapshot Date] = latestDate
    )
)
RETURN out

You'll also see that the series labels were on also. In this case, I much preferred the look of this, compared to having a colour legend. The visual association is established much quicker here, and the density of information around the right-hand-side of the graph is just about right (with the data label and series label together).

#dax #line-graph #power-bi #visual