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
Anonymous
Not applicable

Averagex not working as expected

Hello ,

I have a fact table that contains this two value 

MR_Robot92_1-1645574012252.png

 

i create a measure that return the Qty on hand through the year as below the result of my measure:

MR_Robot92_2-1645574031635.png

 

Now , i want to calculate the average of Qty on hand (previous result) .

 

I create a new measure avg , that call the previous measure like as below : 

 

 

average of Qty on hand = averagex('Fact table',[Qty on hand])

 

As below the result :

MR_Robot92_0-1645573991043.png

 

The result that i get it isn't what i want because i get only that average (238+298)/2  (because i have only two rows on fact table)

 

While  i want to have an average or all the row  ((238*7)+(298*5))/12

 

FYI : I want also that measure work with another context for example if i choose another dimension 

 

Any idea how can i do that ? 

 

Thanks for help !! 

 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous ,

Here are the steps you can follow:

1. Create calculated table.

Date =
CALENDAR(DATE(2019,1,1),DATE(2019,12,31))

2. Create calculated column.

left = VALUE( LEFT( RIGHT('Table'[Date Avaliavle],4),2))

vyangliumsft_0-1645768193701.png

3. Create measure.

Qty_Month =
IF(
    MAX('Date'[Month])>=1&&MAX('Date'[Month])<8,CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=1)),CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=8)))

vyangliumsft_1-1645768193704.png

4. Create calculated table.

Table 2 =
var _table1=SUMMARIZE('Date','Date'[Month],"if",
IF(
    'Date'[Month]>=1&&'Date'[Month]<8,CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=1)),CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=8))))
var _table2=ADDCOLUMNS(_table1,"count",COUNTX(FILTER(_table1,[if]=EARLIER([if])),[Month]))
var _table3=ADDCOLUMNS(_table2,"amount",[if]*[count])
var _table4=SUMMARIZE(_table3,[count],[amount])
return
_table4

vyangliumsft_2-1645768193705.png

5. Create measure.

average of Qty on hand =
DIVIDE( SUMX(ALL('Table 2'),[amount]),SUMX(ALL('Table 2'),[count]))

6. Result:

vyangliumsft_3-1645768193705.png

 

Best Regards,

Liu Yang

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

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi  @Anonymous ,

Here are the steps you can follow:

1. Create calculated table.

Date =
CALENDAR(DATE(2019,1,1),DATE(2019,12,31))

2. Create calculated column.

left = VALUE( LEFT( RIGHT('Table'[Date Avaliavle],4),2))

vyangliumsft_0-1645768193701.png

3. Create measure.

Qty_Month =
IF(
    MAX('Date'[Month])>=1&&MAX('Date'[Month])<8,CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=1)),CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=8)))

vyangliumsft_1-1645768193704.png

4. Create calculated table.

Table 2 =
var _table1=SUMMARIZE('Date','Date'[Month],"if",
IF(
    'Date'[Month]>=1&&'Date'[Month]<8,CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=1)),CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=8))))
var _table2=ADDCOLUMNS(_table1,"count",COUNTX(FILTER(_table1,[if]=EARLIER([if])),[Month]))
var _table3=ADDCOLUMNS(_table2,"amount",[if]*[count])
var _table4=SUMMARIZE(_table3,[count],[amount])
return
_table4

vyangliumsft_2-1645768193705.png

5. Create measure.

average of Qty on hand =
DIVIDE( SUMX(ALL('Table 2'),[amount]),SUMX(ALL('Table 2'),[count]))

6. Result:

vyangliumsft_3-1645768193705.png

 

Best Regards,

Liu Yang

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

amitchandak
Super User
Super User

@Anonymous , Try a measure like

 

average of Qty on hand = averagex(values('Fact table'[Month Year]),[Qty on hand])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak thanks for the reply.

Well your solution doesn't work , in my fact table the granularity is date then i tried that : 

average of Qty on hand = averagex(values('Fact table'[dateid]),[Qty on hand])


The result that i get is like the measure that i created before.
Fyi : as bellow the data that i have on my fact : 

MR_Robot92_0-1645606061409.png

The measure take only those values and calculate the average  (238+298)/2  

 

While  i want to have an average or all the row  ((238*7)+(298*5))/12

 

MR_Robot92_1-1645606148901.png

 

Thanks in advance for your time and help ! 

 



@Anonymous , This should happen at month year level for visual

 

 

average of Qty on hand = averagex(values('Fact table'[Month year]),[Qty on hand])

 

 

or

 

Measure 1 
average of Qty on hand day= averagex(values('Fact table'[dateid]),[Qty on hand])

Measure 2 
average of Qty on hand Month = 
averagex(values('Fact table'[Month Year]),[average of Qty on hand day])

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak 

But what if i want to work for all the level , i need to create all measure for different level ?

i will have a lot of measure ...... There are any solution to optimize that ? 

And also what if i have another dimension in my visual i think the average will only for dimension date and not another dimension 

Thanks

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

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.