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
Dellis81
Continued Contributor
Continued Contributor

AverageX exclude partial year in "total"

Hello!

 

I am needing help in calculating annual averages excluding those years not complete (ie 2020).  The current measure I am using 

CostCenter exclOffsetsAvg =
AVERAGEX ( VALUES ( 'CALENDAR'[Year] ), [CostCenter exclOffsets0] )

Which results in this calculationCapture.PNG,   The individual years are correct - however I would like to exclude 2020, as obvious only partial year.   The real average I want is 15,568.33.

 

I do want to display the 2020 value, but not include in the overall average.

 

 

 

 

 

And while I am asking - is there a way to change the "Total" connotation to "Average"

 

Thanks in advance - I always get tremendous help from this forum!  Appreciated!

2 ACCEPTED SOLUTIONS
parry2k
Super User
Super User

@Dellis81 solution attached, change as per your requirement.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

amitchandak
Super User
Super User

@Dellis81 , Try

CostCenter exclOffsetsAvg =
calculate(AVERAGEX ( VALUES ( 'CALENDAR'[Year] ), [CostCenter exclOffsets0]  ),'CALENDAR'[Year]<Year(Today()))
OR
CostCenter exclOffsetsAvg =
AVERAGEX (filter( VALUES ( 'CALENDAR'[Year] ),'CALENDAR'[Year]<Year(Today())), [CostCenter exclOffsets0]  )

View solution in original post

8 REPLIES 8
amitchandak
Super User
Super User

@Dellis81 , Try

CostCenter exclOffsetsAvg =
calculate(AVERAGEX ( VALUES ( 'CALENDAR'[Year] ), [CostCenter exclOffsets0]  ),'CALENDAR'[Year]<Year(Today()))
OR
CostCenter exclOffsetsAvg =
AVERAGEX (filter( VALUES ( 'CALENDAR'[Year] ),'CALENDAR'[Year]<Year(Today())), [CostCenter exclOffsets0]  )
Dellis81
Continued Contributor
Continued Contributor

Thanks for your help - I was able to use your second measure, wrapped inside an if(hasonevalue) statement.

CostCenter exclOffsets = 


VAR ExclCurrentYrAvg =
    AVERAGEX (
        FILTER ( VALUES ( 'CALENDAR'[Year] ), 'CALENDAR'[Year] < YEAR ( TODAY () ) ),
        [CostCenter exclOffsets0]
    )
RETURN
    IF (
        HASONEVALUE ( 'CALENDAR'[Year] ),
        [CostCenter exclOffsets0],
        ExclCurrentYrAvg
    )

 

Thank you!

Dellis81
Continued Contributor
Continued Contributor

Thank you  - we are closer, but not quite.  Your first formula returned the same value 15,568 for all years and total line.

 

The second formula returned the correct value for 2017,2018,2019, and total.  The 2020 year was blank.  

 

My hope was I could include the 2020 value on it's unique report line, but exclude from the average.

 

Capture4.PNG

 

Thank you!

@Dellis81 no single clue what you need? Originally you asked avg excluding current year and now you are looking for sum and avg.

 

It is very hard to provide a solution when the problem is not clearly defined. We are here to help but you need to help us so that we can provide an effective solution. Read this post to get your answer quickly.

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.  Please only show that table in the file where you are facing a problem.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@Dellis81 solution attached, change as per your requirement.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Dellis81
Continued Contributor
Continued Contributor

Thanks for your suggestion.  Based on your input, plus another forum member, was able to piece together what I needed.   Here is my final measure.    Sum of each individual year, with the Total being the average of each year, excluding current yr.

CostCenter exclOffsets = 


VAR ExclCurrentYrAvg =
    AVERAGEX (
        FILTER ( VALUES ( 'CALENDAR'[Year] ), 'CALENDAR'[Year] < YEAR ( TODAY () ) ),
        [CostCenter exclOffsets0]
    )
RETURN
    IF (
        HASONEVALUE ( 'CALENDAR'[Year] ),
        [CostCenter exclOffsets0],
        ExclCurrentYrAvg
    )

   thank you

Dellis81
Continued Contributor
Continued Contributor

Thanks for your quick response - unfortunately we aren't quite there yet.   I am needing each individual year to be the SUM, however the total line needs to be the average of all complete years.

 

I took your measure - and tweaked.   And as you can see, the result of 3454 is a sum of 2018 and 2019

Annual Sales wAvgTotal = 
IF ( 
    HASONEFILTER ( 'Calendar'[Year] ), 
    [Sum Sales],
    CALCULATE ( AVERAGEx(values('Calendar'[Current Year]), ([Sum Sales] )), 'Calendar'[Current Year] = 0 )
)

I still think I need to be using the averagex iterator - as that works for ALL years.   The remedy is to narrow the years down excluding 2020.   But, as you can see in the second column - I am still pulling in 2020.

 
Annual Sales wAvgTotal =
IF (
HASONEFILTER ( 'Calendar'[Year] ),
[Sum Sales],
CALCULATE ( AVERAGEx(values('Calendar'[Current Year]), ([Sum Sales] )), 'Calendar'[Current Year] = 0 )

 

 

Below is the link to your original file with my foild attempts with yoru dataset
https://drive.google.com/file/d/106gb8DklbFyMiSiLFDYHr0mEbjaX5Kwi/view?usp=sharing

 

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.