Dyota's blog

DAX: data label only on latest dot

When putting on data labels on in Power BI, for line graphs in particular, I don't like how much clutter it puts on when every single data point has a label on it. This is especially true if there are multiple lines on the graph that are close together, and the data labels look like they are jostling for the limited space available.

In the context of line graphs that represent data over time, one trick that I use is to only apply the data label to the most recent data point. Often this is the data point of most interest, and based on this data label, you can judge the others by spatial comparison.

To do this, I set up a measure just for displaying this "most recent data label", and set the data label in the visual to refer to this measure.

There are other useful variations for this, such as displaying the last three, displaying just the first and the last, and so on. In one particular case, I had two line graphs: one representing actuals year-to-date, and one representing budget, over a whole year. For the budget line, I set up the data labels to only show the months that haven't had actuals yet, and the latest month where there was an actual.

I think that being judicious with data labels adds value by taking away clutter, and allows users to get to the most pertinent information more quickly.

Data Label Most Recent =
    VAR context = ALLSELECTED(thisdatatable)

    VAR latestDate = CALCULATE(
        MAXX(
            context,
            [Date]
        ),
        context
    )

    VAR out = CALCULATE(
        SUMX(
            thisdatatable,
            [This Column]
        ),
        FILTER(
            thisdatatable,
            
            // this is the part that dictates which labels show up
            [Date] = latestDate
        )
    )
    RETURN out

#dataviz #dax #powerbi