Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
RafalMonka
Helper I
Helper I

Line chart with Legend and additional measure

Hi,

we have a dashboard with standard Line chart where Axis are months, Legend is UserAssigned and Values – some measure Score.

RafalMonka_2-1641135402322.png

 

 

What we need to do is to place additional measure which will be displaying average value of Scores. Something like here:  

RafalMonka_1-1641135308853.png

 

In PowerBI Line chart when you specify a field in a Legend section you cannot have more than one measure in Values section.

We thought about workaround - adding “virtual” User assigned to the list of users and calculate average score measure for this “virtual” item. But due to a specific reason we cannot do this.

Maybe someone knows the solution? Maybe some custom line chart visual is available?

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@RafalMonka and here is the output:

 

2022-01-03_08-32-01.gif



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

18 REPLIES 18
parry2k
Super User
Super User

@AlexisOlson I see, yes, then it would work. Sorry I missed that part.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@AlexisOlson Unfortunately that will not work, FYI



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Can you elaborate? It appears to work for me.

AlexisOlson_0-1641227879073.png

Note: The slicer is on Table1[User].

 

 

parry2k
Super User
Super User

@RafalMonka and here is the output:

 

2022-01-03_08-32-01.gif



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

You're great! Now it works perfectly. Thank you very much.

parry2k
Super User
Super User

@RafalMonka I see, change the measure to this:

 

ChartValue = 
VAR __users = INTERSECT ( VALUES ( Legend[User] ), VALUES ( Table1[User] ) )
RETURN
IF (
    SELECTEDVALUE ( Legend[User] ) = "Average",
    AVERAGEX ( VALUES ( Table1[User] ), CALCULATE ( SUM ( Table1[Value] ) ) ),
    CALCULATE (
        SUM ( Table1[Value] ),
        TREATAS ( __users, Table1[User] )
        // TREATAS ( VALUES ( Legend[User] ), Table1[User] )
    )
)

 

 

Follow us on LinkedIn and subscribe to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@RafalMonka Don't you have another filter directly filter the table1, if those are then the solution provided by @AlexisOlson should work, let's say you have a table1 filter on a project and only two users are associated with that project, in the solution, it will show only two users, not other users. Seems like you need to tweak your data model if this is not working as expected but the solution provided @AlexisOlson is the way to go.

 

Follow us on LinkedIn and subscribe to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi, 

we have worked on Alexis's example, by adding visual filter Table1[User] and column Table1[Project].

When filtering by Project everything works very well. 

RafalMonka_3-1641226599986.png

 

However, when you try to select users on visual filter Table1[User], the changes are not reflected on Legend[User].

As you can see - user "Zbi" is deselected in visual filter but it still appears in Legend.

 

RafalMonka_2-1641226530839.png

 

Modification of model is not possible.

Is it possible to modify code in order to include in chart Legend only items selected on visual filter Table1[User]?

 

 

Try using KEEPFILTERS.

ChartValue = 
IF (
    SELECTEDVALUE ( Legend[User] ) = "Average",
    AVERAGEX ( VALUES ( Table1[User] ), CALCULATE ( SUM ( Table1[Value] ) ) ),
    CALCULATE (
        SUM ( Table1[Value] ),
        KEEPFILTERS ( TREATAS ( VALUES ( Legend[User] ), Table1[User] ) )
    )
)
RafalMonka
Helper I
Helper I

Hi Alexis,

many thanks for code, but take into account that Legend table should have relationship with Table1.

The reason is that we have multiple filters on dashboard, for instance to limit list of users to certain projects, teams.

So we cannot display all the users from Legend table on a chart.

AlexisOlson
Super User
Super User

@parry2k's suggestion should work. Create a new table to use for the legend

 

Legend = UNION ( VALUES ( Table1[User] ), { "Average" } )

 

Then define a measure to use in the line chart. (Edited to include KEEPFILTERS.)

 

ChartValue = 
IF (
    SELECTEDVALUE ( Legend[User] ) = "Average",
    AVERAGEX ( VALUES ( Table1[User] ), CALCULATE ( SUM ( Table1[Value] ) ) ),
    CALCULATE (
        SUM ( Table1[Value] ),
        KEEPFILTERS ( TREATAS ( VALUES ( Legend[User] ), Table1[User] ) )
    )
)

 

Result:

AlexisOlson_0-1641160304694.png

See attached .pbix.

 

You may want to vote for this Idea:
Line Chart with multiple values fields and legends

parry2k
Super User
Super User

@aj1973, in that case, he has to create measure for every single assigned to user name and not sure it is a scalable solution. Just my 2 cents.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

aj1973
Community Champion
Community Champion

@parry2k Indeed

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

parry2k
Super User
Super User

@RafalMonka not sure about the custom visual but you are on right track, maybe not to add a virtual user in your main user table but create a disconnect user table, add a virtual user in that one and then use that in the visuals, ofcourse it will require to write a new measure to use the disconnected user table.

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

RafalMonka
Helper I
Helper I

Yes, we have. But we have only obtained straight line (average for the whole period).

Average line is based on the measure used in Values field.

RafalMonka_0-1641136499259.png

We need average per certain months, as we have shown on the previous screen.

 

 

@RafalMonka 

You can add as many as you want of measures in Values field, just go to format and turn on the Legend

aj1973_0-1641139084621.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Don't udenrstand - what do you mean by "turn on the Legend"?

When we have a field in Legend section, then we cannot use more than one measure in Values section. 

RafalMonka_1-1641140087854.png

 

Format pane - Legend is On.

RafalMonka_2-1641140220202.png

 

 

 

aj1973
Community Champion
Community Champion

Hi @RafalMonka 

Have you tried adding an Average line here

aj1973_0-1641136293625.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.