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

Dynamic Average calculation based on slicer selection (representing time horizon)

They say a picture says more than 1000 words. Below is what I am hoping to achieve.

 

Have both Sales and a Constant line representing average in a chart but depending on slicers such as region or selection of Financial Years I would like the average to be calculated and shown as a horizontal line for the period. 

sliceNdiceUup_0-1623992641588.png

Is there any way to achieve this in powerpivot/bi? 

 

My challenge is if I tell it to ignore the row filters representing years then the years modified by slicers will also be ignored so it's a catch of 22..  😞 

Copy of AvguSales:= CALCULATE(AVERAGE('AllActSales_table2'[SALES]),ALLEXCEPT(AllActSales_table,AllActSales_table[Period]))

sliceNdiceUup_1-1623993005202.png

 

Any ideas would be greatly appreciated.

1 ACCEPTED SOLUTION

@Fowmy 

Ok here is the solution / workaround that does the job. If there is any better way please let me know:

I created an extra disconnected Calendar table and created slicers for both the disconnected calendar and the connected calendar.

With VBA (busted, yes I work in Excel, my organisation is not ready for PowerBi as of yet) so that only 1 slicer is used I am able to have one slicer control the other, this way the two calendars can remain disconnected.

My 2 Measures are:

  • LotSale:=CALCULATE(SUM(AllActSales_table[SALES (LOTS)]),

FILTER(AllActSales_table,

AllActSales_table[Period] >= MIN(discCalendar[Date]) &&

AllActSales_table[Period] <= MAX(discCalendar[Date])))

  • AvgYield:=CALCULATE(DIVIDE( [LotSale], COUNTROWS(VALUES('discCalendar'[Year]))),

ALLEXCEPT('Calendar',Calendar[Date]))

 

Now depending how the user ajusts the slicers the average (constant horizontal line) for the selected years (and region) will recalibrate:

 

 

sliceNdiceUup_0-1624342226764.png

 

 

 

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@sliceNdiceUup 

This measure should work for you, please try:

Avg Sales = 

CALCULATE(
    AVERAGE('AllActSales_table2'[SALES]),
    ALLSELECTED(AllActSales_table[Period])
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fomy

Thanks mate, appreciate that.

Unfortunately with that formula you allow the row filters representing years within the pivot table to work. Please see image below with your formula and my "desired result". I would like to ignore row filters representing years (on the pivot table) but actually don't ignore it when calculating the average over the selected years via the slicers. I know it's a bit of contradicting requirement which is why I am not sure how to workaround it.

 

sliceNdiceUup_0-1624235956470.png

 

@Fowmy 

Ok here is the solution / workaround that does the job. If there is any better way please let me know:

I created an extra disconnected Calendar table and created slicers for both the disconnected calendar and the connected calendar.

With VBA (busted, yes I work in Excel, my organisation is not ready for PowerBi as of yet) so that only 1 slicer is used I am able to have one slicer control the other, this way the two calendars can remain disconnected.

My 2 Measures are:

  • LotSale:=CALCULATE(SUM(AllActSales_table[SALES (LOTS)]),

FILTER(AllActSales_table,

AllActSales_table[Period] >= MIN(discCalendar[Date]) &&

AllActSales_table[Period] <= MAX(discCalendar[Date])))

  • AvgYield:=CALCULATE(DIVIDE( [LotSale], COUNTROWS(VALUES('discCalendar'[Year]))),

ALLEXCEPT('Calendar',Calendar[Date]))

 

Now depending how the user ajusts the slicers the average (constant horizontal line) for the selected years (and region) will recalibrate:

 

 

sliceNdiceUup_0-1624342226764.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.