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
Mist
Frequent Visitor

Plot a filtered value compared to an average across unfiltered values

Let's say I have monthy sales data for a few companies over one year. I want to plot the average sales across all companies. Easy right! Then I want to add one companies sales to the same plot to allow a comparison to the average. How do I do that?

 

Here's a picture of what I have now:

sales.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I want to show the average line (second line graph) on the first line graph. When I click on CompanyA in the histogram I would like to have a line graph showing just CompanyA data AND the average across all companies.

 

Is that doable?

 

Thanks

1 ACCEPTED SOLUTION
Mist
Frequent Visitor

Here's how I solved it. Instead of separate measures for each company I just created one measure that's the result of the highlighted company:

SalesSelected = CALCULATE(AVERAGE([sales]), ALLSELECTED(sales[company]))

The average line is the same as @chrisu suggested:

AvgSales = CALCULATE(AVERAGE([sales]), ALL(sales[company]))

Thanks @chrisu for puting me on the right track.

sales3.png

View solution in original post

3 REPLIES 3
chrisu
Responsive Resident
Responsive Resident

There's probably a better solution than this, but this has worked for me:

 

1. Because you can either have a legend OR multiple measures on a line chart, you will have to define a measure for each company, like this:

 

CompanyASales = CALCULATE(SUM([sales]), [company] = "CompanyA")

CompanyBSales = CALCULATE(SUM([sales]), [company] = "CompanyB")

 

etc.

 

2. Then create an average sales measure using ALL to override any filters on company:

 

AverageSales = CALCULATE(AVERAGE([sales]), ALL([company]))

 

3. Add all of those measures to the values area of the line chart (you will have to remove company from the legend first).  

Mist
Frequent Visitor

Hi @chrisu, thanks for responding - I was excited when I saw your post as I thought "Yes, that's going to work!". But I don't think it quite does what I wanted. It gets me lines for each company on the chart plus a line for the average across all companies on the same chart which is great and a step further that I'd gotten before (kudos!). I was hoping though that when I filter by CompanyA by clicking on the histogram then ONLY CompanyA AND the average line would remain on the plot, allowing the user to focus on just the difference between the company of interest and the average. Any ideas if this is possible? Here's a pic of where I'm at now.

sales2.png

Mist
Frequent Visitor

Here's how I solved it. Instead of separate measures for each company I just created one measure that's the result of the highlighted company:

SalesSelected = CALCULATE(AVERAGE([sales]), ALLSELECTED(sales[company]))

The average line is the same as @chrisu suggested:

AvgSales = CALCULATE(AVERAGE([sales]), ALL(sales[company]))

Thanks @chrisu for puting me on the right track.

sales3.png

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.