Forum Discussion

Brummitt5043's avatar
Brummitt5043
New Member
3 years ago
Solved

Please Help - How do I create a graph with data labels on line ends?

Hi,   New to power bi, currently transfering a number of reports from one system to another. How do i add data labels to line ends on power BI? I've used similar visualisation tools and this is usu...
  • PaulDBrown's avatar
    3 years ago

    Here are a couple of options to complement the suggestions provided.

    If you add a legend, currently you cannot add more than one measure as values (which you need currently to show the labels for the max month value by year - though I think I've seen this feature demoed in conferences for future releases).

    So the options are:

    1) Create measure for each of the values per year and add them to the y-axis values. The measures follow this pattern:

     

    Sales Current Year = 
    CALCULATE([Sum sales], 'Date Table'[Year] = YEAR(TODAY()))

     

    and 

     

    Max month PY Year = 
    VAR _MXmonth = CALCULATE(MAX('Date Table'[Month]), FILTER(ALL('Date Table'), NOT ISBLANK([Sum sales]) && 'Date Table'[Year] = YEAR(TODAY())-1))
    RETURN
    CALCULATE([Sum sales], FILTER('Date Table', 'Date Table'[Month] = _MXMonth && 'Date Table'[Year] = YEAR(TODAY())-1))

     

    You can now add all the measures to the y-axis bucket, and format each measure to show the corresponding colour

    Two caveats here:

    - Since the measure names aren't dynamic, you are stuck with whichever name you give them (so not future proof)

    - The visual will not fully respond to a slicer

     

    2) Create a fields parameter table with all the measures to use in the visual. Add a Year field to this table.

    Create a new table including the periods and the colour codes:

    Create a one-to-many relationship between the year field in this legend table and the year field in the parameter table. The model looks like this:

    Create the line visual with the measure from the parameter field table and format each measure using the codes from the legend table. Turn on the data labels only for the max month by year values.

    Create a matrix visual with the fields from the Legend table: Year as columns; year as values.

    Hide the header by turning the tex to the same colour as the visual; format (conditional) the year values referencing the codes in the legend table. Overlay (if you wish) the legend over the visual (turn off the legend on the visual). Make sure that "maintain layer order" is set to on under the formatting pane -> general

    If you need to slice by year, create a new dimension table for Year as a bridge table and create the relatiohsips between this Year Table and the Legend and Date table:

     

     

     

    and you will get

     

    Sample PBIX attached