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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
clubspec
Helper III
Helper III

Add an average line to line and stacked column chart

Hi Gurus,

I want to add an average Qty line like below picture on a "line and stacked column chart".  The Qty table is linked to a calendar table.  And there is a slicer for 'Calendar' [Year].  How can I write the dax for this average line even when I drill up or down to see average by year or by quarter.

clubspec_0-1728958037690.png

Appreciate you help in advance, I can't get my head around.

Thanks,

clubspec

 

1 ACCEPTED SOLUTION

I got it working today but had to twist a little bit from your DAX to suit my case.  I cannot use AVERAGEX because my data contains multiple rows in same date or same month so if I used AVERAGEX it would be out.  I had to use SUM instead and created extra calculated columns on the fact table for the year, quarter, and month when transaction happended.  But yes, the ISINSCOPE definitely the way to go.

Average sales: =
SWITCH (
    TRUE (),
    ISINSCOPE ( 'Calendar'[Month] ),
    DIVIDE(CALCULATE(SUM(SALESTABLE[Qty (kg)]),ALLEXCEPT('Calendar','Calendar'[Year])),CALCULATE(DISTINCTCOUNTNOBLANK(SALESTABLE[TRANS_MONTH]),ALLEXCEPT('Calendar','Calendar'[Year]))),
    ISINSCOPE ( 'Calendar'[Quarter] ),
    DIVIDE(CALCULATE(SUM(SALESTABLE[Qty (kg)]),ALLEXCEPT('Calendar','Calendar'[Year])),CALCULATE(DISTINCTCOUNTNOBLANK(SALESTABLE[TRANS_QTR]),ALLEXCEPT('Calendar','Calendar'[Year]))),
    ISINSCOPE ('Calendar'[Year]),
    DIVIDE(CALCULATE(SUM(SALESTABLE[Qty (kg)]),ALLSELECTED('Calendar'[Year])),CALCULATE(DISTINCTCOUNTNOBLANK(SALESTABLE[TRANS_YEAR]),ALLSELECTED('Calendar'[Year]))))

 

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

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

Please try using ISINSCOPE DAX function in the measure, something like below.

 

The visualization has drill down arrow and you can try to click and drill down to year-quarter or to year-month.

 

Jihwan_Kim_1-1728962364416.png

 

 

Jihwan_Kim_0-1728962334226.png

 

ISINSCOPE function (DAX) - DAX | Microsoft Learn

 

Average sales: = 
SWITCH (
    TRUE (),
    ISINSCOPE ( 'calendar'[Year-MOnth] ),
        AVERAGEX (
            ALL (
                'calendar'[Year-MOnth],
                'calendar'[Year-Month sort],
                'calendar'[Year-Quarter]
            ),
            [Sales total:]
        ),
    ISINSCOPE ( 'calendar'[Year-Quarter] ),
        AVERAGEX (
            ALL ( 'calendar'[Year-Quarter] ),
            [Sales total:]
        ),
    ISINSCOPE ( 'calendar'[Year] ),
        AVERAGEX (
            ALL ( 'calendar'[Year] ),
            [Sales total:]
        )
)

 


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you Jihwan_Kim, your dax returns same value as the column value:

clubspec_0-1728964618122.png

Not sure if it is because my Qty table has more rows that got same date and in your example file your sales table has unique date.
I thought it would be something like CALCULATE(SUM(qty),ALL(month)) / DISTINTCOUNT (month) that has data, in this case CALCULATE(SUM(qty),ALL(month)) / 10 months.
But your ISINSCOPE dax definetly will help solving the dynamic of drilling up or down the year, quarter, and month.

Hi,

Thank you for your message, and I think it is because your calendar dimension table has more columns than what I have in my sample.

I think ISINSCOPE is one of DAX functions that you can use in this type of questions.

Thanks.


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

I got it working today but had to twist a little bit from your DAX to suit my case.  I cannot use AVERAGEX because my data contains multiple rows in same date or same month so if I used AVERAGEX it would be out.  I had to use SUM instead and created extra calculated columns on the fact table for the year, quarter, and month when transaction happended.  But yes, the ISINSCOPE definitely the way to go.

Average sales: =
SWITCH (
    TRUE (),
    ISINSCOPE ( 'Calendar'[Month] ),
    DIVIDE(CALCULATE(SUM(SALESTABLE[Qty (kg)]),ALLEXCEPT('Calendar','Calendar'[Year])),CALCULATE(DISTINCTCOUNTNOBLANK(SALESTABLE[TRANS_MONTH]),ALLEXCEPT('Calendar','Calendar'[Year]))),
    ISINSCOPE ( 'Calendar'[Quarter] ),
    DIVIDE(CALCULATE(SUM(SALESTABLE[Qty (kg)]),ALLEXCEPT('Calendar','Calendar'[Year])),CALCULATE(DISTINCTCOUNTNOBLANK(SALESTABLE[TRANS_QTR]),ALLEXCEPT('Calendar','Calendar'[Year]))),
    ISINSCOPE ('Calendar'[Year]),
    DIVIDE(CALCULATE(SUM(SALESTABLE[Qty (kg)]),ALLSELECTED('Calendar'[Year])),CALCULATE(DISTINCTCOUNTNOBLANK(SALESTABLE[TRANS_YEAR]),ALLSELECTED('Calendar'[Year]))))

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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