Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Calculate average of proportion by group

I'm trying to calculate the average of a proportion that was grouped by a category. Per the example below, average of  the proportion of "blank" category within a Fruit.

 

Data:

Fruit_IDCategoryAmount
1 5
1A6
2A7
2 2
2B3
3A0
3B5

 

The calculation would be:

Fruit_ID ABProportion
156 5/11=0.45
22732/12=0.17
3 050/5=0.00

 

The average should be 0.31 averaging fruit 1,2, and 3. However, my formula only considers fruit 1 and 2 and calculates to 0.21, since they have values in the "blank" category and ignored Fruit 3. Technically my Fruit ID is also stored in another table and just has a join. Not sure how to reference the Fruit ID if it was stored in another table either.

 

What's wrong with my formula?

Avg Proportion =
AVERAGEX(
    KEEPFILTERS(VALUES('Table'[Fruit_ID])),
    CALCULATE(SUM('Table'[Amount]), ISBLANK(Table[Category]))/ CALCULATE(SUM('Table'[Amount]),) )
 
Thanks in advance!
1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create measures

por1 =
CALCULATE (
    SUM ( 'Table1'[Amount] ),
    FILTER ( 'Table1', 'Table1'[Category] = BLANK () )
)
    / SUM ( 'Table1'[Amount] )

por2 =
VAR total =
    AVERAGEX ( VALUES ( Table1[Fruit_ID] ), [por1] )
RETURN
    IF ( ISINSCOPE ( Table1[Category] ), SUM ( Table1[Amount] ), total )

 

Or

por3 =
VAR total =
    AVERAGEX ( VALUES ( Table1[Fruit_ID] ), [por1] )
RETURN
    IF (
        ISINSCOPE ( Table1[Category] ),
        FORMAT ( SUM ( Table1[Amount] ), "0" ),
        FORMAT ( total, "0.00" )
    )

Capture5.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
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

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create measures

por1 =
CALCULATE (
    SUM ( 'Table1'[Amount] ),
    FILTER ( 'Table1', 'Table1'[Category] = BLANK () )
)
    / SUM ( 'Table1'[Amount] )

por2 =
VAR total =
    AVERAGEX ( VALUES ( Table1[Fruit_ID] ), [por1] )
RETURN
    IF ( ISINSCOPE ( Table1[Category] ), SUM ( Table1[Amount] ), total )

 

Or

por3 =
VAR total =
    AVERAGEX ( VALUES ( Table1[Fruit_ID] ), [por1] )
RETURN
    IF (
        ISINSCOPE ( Table1[Category] ),
        FORMAT ( SUM ( Table1[Amount] ), "0" ),
        FORMAT ( total, "0.00" )
    )

Capture5.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

parry2k
Super User
Super User

@Anonymous can you share how does your raw data looks like? and how tables are related? 



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.

Anonymous
Not applicable

hi @parry2k , I realized I don't need to reference or join another table, so that part is ok. But my raw data essentially looks like the data table I posted above. Or do you need more information?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors