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
Alice08
Helper I
Helper I

Power BI desktop query - bar chart

I want to add an average line in a bar chart visual which looks like below -

 

Alice08_0-1708874830261.png

 

Legends - Year (2023 and 2024)

condition is it should only diplay the average value for year 2023 and it should display both years data as well.

is ther any way we can achieve this?

 

1 ACCEPTED SOLUTION
v-kaiyue-msft
Community Support
Community Support

Hi @Alice08 ,

1. Create a measure, write an expression, and calculate the desired average. The following expression calculates the average monthly sales in 2013.

Measure =
VAR _sum = CALCULATE(SUM(financials[Sales]),FILTER(ALL('financials'),'financials'[Year] = "2013"))
VAR _num = CALCULATE(DISTINCTCOUNT('financials'[Month Number]),FILTER(ALL('financials'),'financials'[Year] = "2013"))
RETURN
DIVIDE(_sum,_num)

2. Click the magnifying glass in the visualizations pane->constant line->add line.
line -> value -> fx, put the created measure value.

vkaiyuemsft_0-1709003788089.png

 

vkaiyuemsft_1-1709003788090.png

3. The final result is shown in the figure below.

vkaiyuemsft_2-1709003815831.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-kaiyue-msft
Community Support
Community Support

Hi @Alice08 ,

1. Create a measure, write an expression, and calculate the desired average. The following expression calculates the average monthly sales in 2013.

Measure =
VAR _sum = CALCULATE(SUM(financials[Sales]),FILTER(ALL('financials'),'financials'[Year] = "2013"))
VAR _num = CALCULATE(DISTINCTCOUNT('financials'[Month Number]),FILTER(ALL('financials'),'financials'[Year] = "2013"))
RETURN
DIVIDE(_sum,_num)

2. Click the magnifying glass in the visualizations pane->constant line->add line.
line -> value -> fx, put the created measure value.

vkaiyuemsft_0-1709003788089.png

 

vkaiyuemsft_1-1709003788090.png

3. The final result is shown in the figure below.

vkaiyuemsft_2-1709003815831.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Use the "Line and Clustered Column Chart" and provide your own measure for the 2023 average (as the line)

Can you elaborate please?

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

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.