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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
cookm01
Regular Visitor

Creating two straight average lines on a bar chart

Hello,

 

I am currently trying to create two straight average lines for a bar chart, to represent the averages for two years on the chart.

 

The context (using dummy data): I have a bar chart which shows clients' costs as a % of income in 2023 and 2024. The bar chart is filtered to only show the data from 2024, but I want to have two lines that demonstrate the average from 2023 and 2024 for all customers going across this. The average is to be created as an aggregate (just adding them up and dividing by total number of clients). I currently get the average line on the bar chart but it is not straight (it is the average for each customer rather than the total year).

 

Please find attached dummy data and example of table without lines below.

 

TIA

 

 

Year Customer% of income 
2024Customer A10%
2024Customer B 40%
2024Customer C70%
2024Customer D20%
2024Customer E60%
2024Customer F50%
2024Customer G30%
2024Customer H50%
2024Customer I90%
2024Customer J80%
2023Customer A20%
2023Customer B 40%
2023Customer C60%
2023Customer D30%
2023Customer E80%
2023Customer F90%
2023Customer G50%
2023Customer H10%
2023Customer I40%
2023Customer J60%

 

cookm01_0-1728552129774.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @cookm01 ,

I create a table as you mentioned.

vyilongmsft_0-1728631118634.png

Then I create a measure and here is the DAX code.

Measure = 
VAR _currentYear =
    MAX ( 'Table'[Year ] )
RETURN
    CALCULATE (
        AVERAGE ( 'Table'[% of income ] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Year ] = _currentYear )
    )

vyilongmsft_1-1728631386901.png

Finally you will see what you want.

vyilongmsft_2-1728631453772.png

vyilongmsft_3-1728631481400.png

 

 

Best Regards

Yilong Zhou

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

3 REPLIES 3
Anonymous
Not applicable

Hi @cookm01 ,

I create a table as you mentioned.

vyilongmsft_0-1728631118634.png

Then I create a measure and here is the DAX code.

Measure = 
VAR _currentYear =
    MAX ( 'Table'[Year ] )
RETURN
    CALCULATE (
        AVERAGE ( 'Table'[% of income ] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Year ] = _currentYear )
    )

vyilongmsft_1-1728631386901.png

Finally you will see what you want.

vyilongmsft_2-1728631453772.png

vyilongmsft_3-1728631481400.png

 

 

Best Regards

Yilong Zhou

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

@Anonymous 

 

Not sure this is exactly what the OP asked for so not sure why it's been marked as the solution.

 

The bar chart is filtered to only show the data from 2024, but I want to have two lines that demonstrate the average from 2023 and 2024 for all customers going across this.

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

@cookm01 

 

Try these 

 

2023 Avg = CALCULATE(AVERAGE('DataTable'[% of income ]), ALLEXCEPT('DataTable','DataTable'[% of income ]),'DataTable'[Year ] = 2023)

 

2024 Avg = CALCULATE(AVERAGE('DataTable'[% of income ]), ALLEXCEPT('DataTable','DataTable'[% of income ]),'DataTable'[Year ] = 2024)

 

regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.