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

Matrix: Averaging Column instead of Total(SUM)

Hello Everyone, 

 

I'm new to Power BI and trying to achieve Total average in a matrix table. Below is th sample data:

ProductStateCustomerRFI_HOURSRFP_HOURSRFQ_HOURS
AILMED510 
BCATESLA3810
CNYBMW 5 
DTXBENZ688
ACOHONDA3 6
BCATESLA321
BMIFORD 55
BCAJAGUAR154


RESULT: 

 

ProductAVG_RFIAVG_RFPAVG_RFQ
A4106
B3.56..676.67
C 5 
D688
Totalavg4.57.6666676.89

 

But in PBI I see the total avg values are bit off :

ProductAVG_RFIAVG_RFPAVG_RFQ
A4106
B3.56..676.67
C 5 
D688
Totalavg4.27.176.8

 

I have attached PBI file_Avg  with sample data for your reference. Formula I'm using to summarize the data by creating new table.

DAX Formula : 

Table = SUMMARIZE(Sheet1,Sheet1[Product],Sheet1[State],Sheet1[Customer],"avg_RFI",SUM(Sheet1[RFI_HOURS]),"avg_RFP",SUM(Sheet1[RFP_HOURS]),"avg_RFQ",SUM(Sheet1[RFQ_HOURS]))
 
Questions:
I'm trying to figure the error ?
Is it a right approach for the Total_avg by column ?
Also, How can we  dispaly Total_avg by row?
 
Thanks in advance. Appreciate for your help !!!

 

3 ACCEPTED SOLUTIONS
v-gizhi-msft
Community Support
Community Support

Hi,

 

Please take following steps:

1)Try to create a new column:

Customer&State = 'Table'[Customer]&"-"&'Table'[State]

2)Try these three measures:

Avg_RFI = 
AVERAGEX (
    DISTINCT ( 'Table'[Product] ),
    CALCULATE (
        SUM ( 'Table'[RFI_HOURS] )
            / CALCULATE (
                DISTINCTCOUNT ( 'Table'[Customer&State] ),
                FILTER ( 'Table', 'Table'[RFI_HOURS] <> BLANK () )
            )
    )
)
Avg_RFP =
AVERAGEX (
    DISTINCT ( 'Table'[Product] ),
    CALCULATE (
        SUM ( 'Table'[RFP_HOURS] )
            / CALCULATE (
                DISTINCTCOUNT ( 'Table'[Customer&State] ),
                FILTER ( 'Table', 'Table'[RFP_HOURS] <> BLANK () )
            )
    )
)
Avg_RFQ =
AVERAGEX (
    DISTINCT ( 'Table'[Product] ),
    CALCULATE (
        SUM ( 'Table'[RFQ_HOURS] )
            / CALCULATE (
                DISTINCTCOUNT ( 'Table'[Customer&State] ),
                FILTER ( 'Table', 'Table'[RFQ_HOURS] <> BLANK () )
            )
    )
)

3)The result shows:

40.PNG

Note that the result 7.66 in your posted expected result screenshot is not correct, (10+6.67+5+8)=7.42 is the right average result.

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto

View solution in original post

v-gizhi-msft
Community Support
Community Support

Hi,

 

Just now i find another easier way to reach your requirement.

Please take following steps:

1)Replace all null value in original table with 0.

2)Unpivot [RFI_HOURS], [RFP_HOURS] and [RFQ_HOURS] columns.

3)After Apply&Close, create this column first:

Customer&State = 'Table (2)'[Customer]&"-"&'Table (2)'[State]

4)Try this measure:

Measure = 
AVERAGEX (
    GROUPBY ( 'Table (2)', 'Table (2)'[Product], 'Table (2)'[Attribute] ),
    CALCULATE (
        DIVIDE (
            SUM ( 'Table (2)'[Value] ),
            CALCULATE (
                DISTINCTCOUNT ( 'Table (2)'[Customer&State] ),
                'Table (2)'[Value] <> BLANK ()
            ),
            BLANK ()
        )
  ))

5)The result shows:

50.PNG

Here is my changed pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto

 

View solution in original post

Anonymous
Not applicable

@v-gizhi-msft Thanks for Solutions this works 🙂 .Will try the easy way too. 👍

Is there a way we can add Total avg by each row for this? and can you suggest some blogs or material practice DAX.

 

View solution in original post

5 REPLIES 5
v-gizhi-msft
Community Support
Community Support

Hi,

 

Just now i find another easier way to reach your requirement.

Please take following steps:

1)Replace all null value in original table with 0.

2)Unpivot [RFI_HOURS], [RFP_HOURS] and [RFQ_HOURS] columns.

3)After Apply&Close, create this column first:

Customer&State = 'Table (2)'[Customer]&"-"&'Table (2)'[State]

4)Try this measure:

Measure = 
AVERAGEX (
    GROUPBY ( 'Table (2)', 'Table (2)'[Product], 'Table (2)'[Attribute] ),
    CALCULATE (
        DIVIDE (
            SUM ( 'Table (2)'[Value] ),
            CALCULATE (
                DISTINCTCOUNT ( 'Table (2)'[Customer&State] ),
                'Table (2)'[Value] <> BLANK ()
            ),
            BLANK ()
        )
  ))

5)The result shows:

50.PNG

Here is my changed pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto

 

v-gizhi-msft
Community Support
Community Support

Hi,

 

Please take following steps:

1)Try to create a new column:

Customer&State = 'Table'[Customer]&"-"&'Table'[State]

2)Try these three measures:

Avg_RFI = 
AVERAGEX (
    DISTINCT ( 'Table'[Product] ),
    CALCULATE (
        SUM ( 'Table'[RFI_HOURS] )
            / CALCULATE (
                DISTINCTCOUNT ( 'Table'[Customer&State] ),
                FILTER ( 'Table', 'Table'[RFI_HOURS] <> BLANK () )
            )
    )
)
Avg_RFP =
AVERAGEX (
    DISTINCT ( 'Table'[Product] ),
    CALCULATE (
        SUM ( 'Table'[RFP_HOURS] )
            / CALCULATE (
                DISTINCTCOUNT ( 'Table'[Customer&State] ),
                FILTER ( 'Table', 'Table'[RFP_HOURS] <> BLANK () )
            )
    )
)
Avg_RFQ =
AVERAGEX (
    DISTINCT ( 'Table'[Product] ),
    CALCULATE (
        SUM ( 'Table'[RFQ_HOURS] )
            / CALCULATE (
                DISTINCTCOUNT ( 'Table'[Customer&State] ),
                FILTER ( 'Table', 'Table'[RFQ_HOURS] <> BLANK () )
            )
    )
)

3)The result shows:

40.PNG

Note that the result 7.66 in your posted expected result screenshot is not correct, (10+6.67+5+8)=7.42 is the right average result.

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto

Anonymous
Not applicable

@v-gizhi-msft Thanks for Solutions this works 🙂 .Will try the easy way too. 👍

Is there a way we can add Total avg by each row for this? and can you suggest some blogs or material practice DAX.

 

amitchandak
Super User
Super User

@Anonymous 

Each one, you have to do like this

new measure =Averagex(SUMMARIZE(Sheet1,Sheet1[Product],"avg_RFI",SUM(Sheet1[RFI_HOURS])),[avg_RFI])

 

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

 

You have to first do sum then Avg.

Anonymous
Not applicable

Hi @amitchandak, I tried this earlier it didn't work. Thanks for the response 👍

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.