Date as legend in line chart

Hi there,

I am plotting the average temperature of last 5 days in the line chart as shown in the picture.

I want to replace the legends of the line chart with actual dates. For example, instead of Today, it should display the date i.e. 14-7-2022. I tried a couple of ways but could not able to make it right. Any help would be really appreciated.

Sample file:
sample.pbix (606.2 KB)

1 Like

The reason your values are named like that is because those are the measure names.

The easiest way to fix this, would be a four-step process:

  1. replaced all of your measures with a single measure:
    Avg Temp = CALCULATE(AVERAGE(IOT_DATA_VIEW[TEMPERATURE]))

  2. add a column to your date table (in Power Query) that creates a DateOffset (I added this after the table was built with the Date Query - so the previous step is “Source”):
    Table.AddColumn(Source, "DateOffset", each Number.From([Date]) - Number.From(Date.From(DateTime.FixedLocalNow())), type number)

  3. On your line chart, add the DateOffset to the “Filters on this Visual” area in the Filter Pane (note that for my screen-shot, I have used the WeekOffset because I could not actually edit your code without losing the IOT_DATA_VIEW table data) - and set the filter to is less than or equal to 0, and is greater than or equal to -3

  4. Add the Date from your calendar table to the legend area of your chart:
    image

your result should look something like this:

3 Likes