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
Noeleke1301
Helper II
Helper II

AVERAGEX with extra rows

Hi all,

 

I'm trying to calculate an average of a percentage. However, based on a measure that counts specific events, I want to include extra rows to be averaged.

 

For example, the following table:

130%
220%
350%
4

100%

 

The average of above is 50%

 

If the measure counts 2 occurences, I want to add 0% for each occurence. So like this:

130%
220%
350%
4

100%

5

0%

6

0%

 

Now the average of the table is 33.33%

 

My current DAX seems to take the extra rows into account when calculating (the average changes when I change 0 to 1 for example), but never returns the correct average percentage.

Basically I select 2 column from table1 (one dummy + one with the percentage rows) and UNION it on a self-generated table that generates the amount of rows that the measure counts, then adds a 0% for each row.

 

Average with extra rows = 
var _count = [count measure]
return

AVERAGEX( 
    UNION( 
        SELECTCOLUMNS( Table1 , "Col1" , Table1[col1] ,"Pct" , AVERAGE( Table1[Pct] ) ) , 
    ADDCOLUMNS( GENERATESERIES( 0 , _count ) , "Pct" , 0 ) )  , 
    [Pct] )

 

 

Please help, thanks

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @Noeleke1301 ,

 

We can create this measure.

Average with extra rows = 
var _count = [count measure]
return

AVERAGEX( 
    UNION( 
        SELECTCOLUMNS( Table1 , "Col1" , Table1[col1] ,"Pct" , Table1[Pct] )  , 
    ADDCOLUMNS( GENERATESERIES( 0 , _count-1 ) , "Pct" , 0 ) )  , 
    [Pct] )

If the measure counts 2 occurences, the average of the table is 33.33%.

vtangjiemsft_0-1708654410917.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

2 REPLIES 2
v-tangjie-msft
Community Support
Community Support

Hi @Noeleke1301 ,

 

We can create this measure.

Average with extra rows = 
var _count = [count measure]
return

AVERAGEX( 
    UNION( 
        SELECTCOLUMNS( Table1 , "Col1" , Table1[col1] ,"Pct" , Table1[Pct] )  , 
    ADDCOLUMNS( GENERATESERIES( 0 , _count-1 ) , "Pct" , 0 ) )  , 
    [Pct] )

If the measure counts 2 occurences, the average of the table is 33.33%.

vtangjiemsft_0-1708654410917.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Awesome, thanks so much! Those tweaks you did made it work beautifully, exactly what I wanted.

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.