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
andreaturri27
Helper I
Helper I

calculate avarege cost

Hi community, 

i would calculate avarege cost into onther column.

avarege cost for 2017 is 207,20 SUM (INVRSN, posting date 2017) = (207.20+207.20+207.20) / (1+1+1)

avarege cost for 2018 is 207.20 SUM (INVRSN, posting date 2017/2018) =(207.20+207.20+207.20+207.20+207.20+207.20) / (1+1+1+1+1+1)

avarege cost for 2019 is 221.60 SUM (INVRSN, posting date 2018/2019) =(207,20+207.20 +693.60)/(1+1+3)

costo medio.PNG

How with dax?

 

thank you.

 

 

6 REPLIES 6
V-pazhen-msft
Community Support
Community Support

@andreaturri27 

 

You should use Allexcept in this case becasue you want two year average.

You can create either measure or column, see the dax with my sample:

 

Measure = CALCULATE(AVERAGE('Table'[Value]),FILTER(ALL('Table'),SUMX(FILTER('Table',EARLIER('Table'[Posting date].[Year])='Table'[Posting date].[Year]||EARLIER('Table'[Posting date].[Year])='Table'[Posting date].[Year]-1),1)))
Column = CALCULATE(AVERAGE('Table'[Value]),FILTER('Table','Table'[Posting date].[Year]=EARLIER('Table'[Posting date].[Year])||'Table'[Posting date].[Year]=EARLIER('Table'[Posting date].[Year])-1))

 

 average this year and last year.JPG

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

Hi @V-pazhen-msft ,

 

thank you for the replay but the value on row is not correct.

i use 

CALCULATE(AVERAGE(MA_InventoryEntriesDetail[LineAmount]);FILTER(ALL(MA_InventoryEntriesDetail);SUMX(FILTER(MA_InventoryEntriesDetail;EARLIER(MA_InventoryEntriesDetail[PostingDate].[Anno])=MA_InventoryEntriesDetail[PostingDate].[Anno]||EARLIER(MA_InventoryEntriesDetail[PostingDate].[Anno])=MA_InventoryEntriesDetail[PostingDate].[Anno]-1);1)))
test22.PNG

 

 

 

 

 

 

 

 

 

 

but the total correct for  year 2017 --> 207,200 , for  year 2018--> 207,200 for  year 2019 --> 221,600 for year 2020 --> 221,600

 

@andreaturri27 

It seems you have used show in SUM for LineAMount, where my example showed in Dont Summarize, Can you share that sample pbix so I can get a look into it for an absolute solution.

 

Paul

hi @V-pazhen-msft thank you for the replay click here to download the file. 

 

Andrea

 

 

amitchandak
Super User
Super User

I think you use allexcept. Create a year column that would be better

refer : you need on allexcept part of it

https://community.powerbi.com/t5/Desktop/Percentage-of-subtotal/td-p/95390

https://community.powerbi.com/t5/Desktop/SUM-of-AVERAGE/td-p/197013

Can you expand on that idea with with an example please @amitchandak ?

 

thank you

 

Andrea

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.