Creating Dynamic Legends in Charts for This Year, Last Year, Etc

Hi
I am trying to create dynamic legends in charts. Right now, I have a chart showing This Years taxes and Last Years taxes with measures. In the chart, the legend is showing the name of the measure, (this Years Taxes and Last Years Taxes) not the year that it represents (like 2021 and 2020). I have searched on the internet, but am not finding anything that will help me accomplish this goal. Does anyone have any suggestions?

Any suggestions would be greatly appreciated.

Thank you

Hello @tjohnson,

Thank You for posting your query onto the Forum.

Well, Power BI doesn’t have the option of “Dynamic Legends” as of now which converts the measures naming convention based onto the slicer selection therefore the result that you’re tring to achieve is not possible. But you can try the option of “Dynamic Headers” as an alternative. Below is the screenshot provided for the reference -

I’m also attaching the working of the PBIX file so that you can review how it’s been worked out.

Hoping you find this useful. :slightly_smiling_face:

Thanks and Warm Regards,
Harsh

Dynamic Headers - Harsh.pbix (24.2 KB)

1 Like

Thank you so much, Harsh! I will look over this and see how to implement. I may have a few questions about some of the formulas as I work through it.

I am going to see if I can add the color of the legend into the cards. Then maybe I can just make these smaller and put above the chart and remove the automatic legend.

I really do appreciate your help!

Tamera

Hello @tjohnson,

For this query as you’ve stated, “I am going to see if I can add the color of the legend into the cards. Then maybe I can just make these smaller and put above the chart and remove the automatic legend.”

There’s a exactly a same video which might meet your requirements that you’ve been looking for. I’m providing a link of video below for the reference which was created by Patrick from Guy In a Cube channel.

Hoping you find this useful. :slightly_smiling_face:

Thanks and Warm Regards,
Harsh

Harsh

Thank you for the reference of the video–I had used this for something else in my file–but I had never done the automatic formatting from the field. I fixed this for my other visualization that I had.

My question is–how would I use this for the purpose of Current Year and Previous Year? These are measures, not a table. The years are in the date table, but Current Year and Previous year are measures–I am not sure how to assign the color to the measure to be able to use the colors in the legend through conditional formatting that Patrick demonstrated. Any ideas?

Thank yo so much for assisting me. This has been very helpful.

Tamera

Hello @tjohnson,

Well, I’m sorry to say but as suggested earlier “Legends” section doesn’t have the option of “Conditional Formatting” wherein we can change the colors, measure names, etc dynamically.

I’m providing the link of my Google Drive from where you can download the PBIX file for the reference that Patrick has used into the video so that you can review the file. Also below is the screenshot provided of the measure that he has created for color coding purposes -

Hoping you find this useful and meets your requirements that you’ve been looking for. :slightly_smiling_face:

Note: When you click onto the link it’ll require the access so just wait for few minutes till the access is granted.

Thanks and Warm Regards,
Harsh

https://drive.google.com/file/d/1N9t8TO16RZtJdTDrnG2dO6izB5pSVbSq/view?usp=sharing

Thank you, Harsh, for sharing this with me.

I don’t know if I am not understanding or not, but what I am trying to figure out as to how to apply my situation to this one. On the airline situation, there is a claim status for each transaction in a table–as shown in the claim status table. Therefore, the measure that compares the claim status ID to the color will work.

In my situation, “Current Calendar Year” and Previous Calendar Year" are not in a table–they are only present in a measure–

in the date table–there are years, 2021, 2020, 2019, etc.–they are not labeled “Current Year” and “Previous Year” except through a measure.

So, how do I take the “Current Calendar Year” and assign a field value to it?
image

I made the table that is pictured above–however, it isn’t connected to anything.

Maybe I am missing something, but I am not seeing how this will work in my situation.

What I did do, however, was take the scenario that you gave me and made a few additional measures.

Current Calendar Year = SELECTEDVALUE(dDate[CalYear])
Current Year Icon = " • "
Current Fiscal Year and Icon = [Current Fiscal Year]& [Current Year Icon]

Previous Calendar Year = SELECTEDVALUE(dDate[CalYear]) -1
prev Year Icon = " • "
PY CalIcon = [Previous Calendar Year]& [prev Year Icon]

I then put the items into a table, made the headings to be a font color of white so that they would not show, and put it above the table–I formatted each column to be the same color as the bar chart for the individual year indicated. I then removed the legend from the chart.

image

I would have to do this for each chart–so I would rather get the idea that you have above working. I just am not sure how to do it. Let me know if I am missing something. Thank you!

Hello @tjohnson,

To be honest, now I’m not sure how should I help further on this. The requirements that you’ve stated in the first half of the aforementioned post is absolutely not understandable to me and this requirements were never mentioned during the initial post of the question.

And now, if you’re looking for the more ideas about how to present it further than please refer the courses that are available onto our education portal for more understanding.

If you’ve to create this type of formatting for each chart that you can overlay one visualization over the other using the “Bookmarks” technique. I’m providing few of the links below from where you can get the ideas about how to present it further. For furthermore ideas, please explore the education portal. I’ve tried my best to help you in this scenario so now please go through the courses and education materials for more clarity and for exploration of the ideas available onto our portal.

Thanks and Warm Regards,
Harsh

Harsh–wow–You have been more than helpful. I will read through these ideas and I am sure I will gain valuable knowledge. I will mark your first post as answered. I appreciate all the time that you put into this!

Thank you!

Tamera

1 Like

Hello @tjohnson,

You’re Welcome. :slightly_smiling_face:

I’m glad that I was able to assist you on this.

Thanks and Warm Regards,
Harsh