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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
vk_pbi
Resolver II
Resolver II

Yearly Average straight line in Column chart

Hi,

I am trying to write a measure which can calculate the yearly average and show it as straight line in stacked column chart. The measure works fine if my chart granularity is at year, if I moved it to months-year (format Jan-22), then it calculates average for each month, not giving a straight line. 

The requirement is to calculate the Yr Avg column. 

 

vk_pbi_0-1684645791859.png

 

 Thanks

1 ACCEPTED SOLUTION

Hi,

Please try something like below.

 

Avg. expected outcome V2: =
IF (
    NOT ISBLANK ( [Values measure:] ),
    AVERAGEX (
        FILTER (
            ALL ( 'Calendar'[Month-Year], 'Calendar'[Month-Year sort], 'Calendar'[Year] ),
            'Calendar'[Year] = MAX ( 'Calendar'[Year] )
        ),
        [Values measure:]
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1684649092375.png

 

Jihwan_Kim_1-1684649427349.png

 

 

Avg. expected outcome: =
IF (
    NOT ISBLANK ( [Values measure:] ),
    CALCULATE (
        AVERAGEX ( VALUES ( 'Calendar'[Month-Year] ), [Values measure:] ),
        WINDOW (
            1,
            ABS,
            -1,
            ABS,
            ALL ( 'Calendar'[Year], 'Calendar'[Month-Year], 'Calendar'[Month-Year sort] ),
            ORDERBY ( 'Calendar'[Month-Year sort], ASC ),
            KEEP,
            PARTITIONBY ( 'Calendar'[Year] )
        )
    )
)

 

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Hi @Jihwan_Kim ,

Thanks for your quick reply. As I am using older version of power BI report server (ver May 2021), in which WINDOW function is not available.
Could you plesae suggest me alternate solution ?

 

Thanks

Hi,

Please try something like below.

 

Avg. expected outcome V2: =
IF (
    NOT ISBLANK ( [Values measure:] ),
    AVERAGEX (
        FILTER (
            ALL ( 'Calendar'[Month-Year], 'Calendar'[Month-Year sort], 'Calendar'[Year] ),
            'Calendar'[Year] = MAX ( 'Calendar'[Year] )
        ),
        [Values measure:]
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Thanks @Jihwan_Kim 

I have used the below measure

CALCULATE(

      AVERAGEX(

                 VALUES('Date'[Month]),

                  [Total Sales]

        ),

         REMOVEFILTERS('Date'),

         VALUES('Date'[Year])

)

         

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors