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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
MeyerRy
Frequent Visitor

Matrix Grand Total - Summing the Row Averages

I need help getting a measure to sum the row totals for the grand total value. The measure below produces the following output. The grand total box is taking averaging the 3 column totals (highlighted in yellow). I want the grand total to sum the row totals (highlighted in green). How can I accomplish this?

Test2 =
AVERAGEX(
    VALUES(EstimateSummaryDataDetails[EstimateName]),
    CALCULATE(SUM(CostUnpivot[TotalCost]))
)

 

MeyerRy_0-1717432073540.png

 

1 ACCEPTED SOLUTION
MeyerRy
Frequent Visitor

I managed to get a working measure based on the help from @Anonymous. You helped point me in the right direction. The following measure will give me the answer I was looking for but what I failed to anticapte was if I changed the cost breakdown structure (the rows on the left) to a different one that had more blanks in the data. The Grand Total cost will change. Which technically is doing what I wanted but from a user standpoint the Grand Total cost changing will immediatdly cause distrust with the data.  What I am going to end up doing is just taking the total cost of each row and dividing by number of projects to get the average cost. That is a much easier measure to create. I am not sure if this will help others in the future but here is the measure:

Total Cost with Grand Total Summing Matrix Row Totals = 
VAR RowTotal = 
    SUMX(
        SUMMARIZE(
            'Table',
            'Table'[CBSValue],
            "@TotalCost",
                SUMX(
                    FILTER(
                        'Table',
                        'Table'[CBSValue] = EARLIER('Table'[CBSValue])
                    ),
                    IF(NOT(ISBLANK('Table'[TotalCost])), 'Table'[TotalCost], BLANK())
                )
        ),
        [@TotalCost]
    )
VAR NonBlankCount = 
    SUMX(
        SUMMARIZE(
            'Table',
            'Table'[CBSValue],
            "@Count",
                COUNTX(
                    FILTER(
                        'Table',
                        'Table'[CBSValue] = EARLIER('Table'[CBSValue])
                    ),
                    IF(NOT(ISBLANK('Table'[TotalCost])), 'Table'[TotalCost], BLANK())
                )
        ),
        [@Count]
    )
VAR RowAverage = 
    DIVIDE(RowTotal, NonBlankCount, 0) -- Divide by NonBlankCount, if it is 0 then use 0 as default
RETURN
IF(
    ISINSCOPE('Table'[CBSValue]), 
    RowAverage,
    SUMX(
        SUMMARIZE(
            'Table',
            'Table'[CBSValue],
            "@RowTotal",
                SUMX(
                    FILTER(
                        'Table',
                        'Table'[CBSValue] = EARLIER('Table'[CBSValue])
                    ),
                    IF(NOT(ISBLANK('Table'[TotalCost])), 'Table'[TotalCost], BLANK())
                ),
            "@NonBlankCount",
                COUNTX(
                    FILTER(
                        'Table',
                        'Table'[CBSValue] = EARLIER('Table'[CBSValue])
                    ),
                    IF(NOT(ISBLANK('Table'[TotalCost])), 'Table'[TotalCost], BLANK())
                )
        ),
        DIVIDE([@RowTotal], [@NonBlankCount], 0)
    )
)

 

View solution in original post

4 REPLIES 4
MeyerRy
Frequent Visitor

I managed to get a working measure based on the help from @Anonymous. You helped point me in the right direction. The following measure will give me the answer I was looking for but what I failed to anticapte was if I changed the cost breakdown structure (the rows on the left) to a different one that had more blanks in the data. The Grand Total cost will change. Which technically is doing what I wanted but from a user standpoint the Grand Total cost changing will immediatdly cause distrust with the data.  What I am going to end up doing is just taking the total cost of each row and dividing by number of projects to get the average cost. That is a much easier measure to create. I am not sure if this will help others in the future but here is the measure:

Total Cost with Grand Total Summing Matrix Row Totals = 
VAR RowTotal = 
    SUMX(
        SUMMARIZE(
            'Table',
            'Table'[CBSValue],
            "@TotalCost",
                SUMX(
                    FILTER(
                        'Table',
                        'Table'[CBSValue] = EARLIER('Table'[CBSValue])
                    ),
                    IF(NOT(ISBLANK('Table'[TotalCost])), 'Table'[TotalCost], BLANK())
                )
        ),
        [@TotalCost]
    )
VAR NonBlankCount = 
    SUMX(
        SUMMARIZE(
            'Table',
            'Table'[CBSValue],
            "@Count",
                COUNTX(
                    FILTER(
                        'Table',
                        'Table'[CBSValue] = EARLIER('Table'[CBSValue])
                    ),
                    IF(NOT(ISBLANK('Table'[TotalCost])), 'Table'[TotalCost], BLANK())
                )
        ),
        [@Count]
    )
VAR RowAverage = 
    DIVIDE(RowTotal, NonBlankCount, 0) -- Divide by NonBlankCount, if it is 0 then use 0 as default
RETURN
IF(
    ISINSCOPE('Table'[CBSValue]), 
    RowAverage,
    SUMX(
        SUMMARIZE(
            'Table',
            'Table'[CBSValue],
            "@RowTotal",
                SUMX(
                    FILTER(
                        'Table',
                        'Table'[CBSValue] = EARLIER('Table'[CBSValue])
                    ),
                    IF(NOT(ISBLANK('Table'[TotalCost])), 'Table'[TotalCost], BLANK())
                ),
            "@NonBlankCount",
                COUNTX(
                    FILTER(
                        'Table',
                        'Table'[CBSValue] = EARLIER('Table'[CBSValue])
                    ),
                    IF(NOT(ISBLANK('Table'[TotalCost])), 'Table'[TotalCost], BLANK())
                )
        ),
        DIVIDE([@RowTotal], [@NonBlankCount], 0)
    )
)

 

MeyerRy
Frequent Visitor

Here is a link to a test power BI dashboard with the data added in. Hopefully that will help out.
TestData.pbix

Anonymous
Not applicable

Hi @MeyerRy ,

I create a table as you mentioned.

vyilongmsft_0-1717470650711.png

Then I create two measures and here are the DAX codes.

Column = SUMX('Table','Table'[A]+'Table'[B]+'Table'[C])/3
Row =
(
    MAX ( 'Table'[A] ) + MAX ( 'Table'[B] )
        + MAX ( 'Table'[C] )
)
    / (
        COUNT ( 'Table'[A] ) + COUNT ( 'Table'[B] )
            + COUNT ( 'Table'[C] )
    )

vyilongmsft_1-1717470814258.png

Finally I create a measure and get what you want.

Column+Row = 'Table'[Column]+'Table'[Row]

vyilongmsft_2-1717470891574.png

 

 

 

Best Regards

Yilong Zhou

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

@Anonymous Interesting formulas. Unfornataly the $88.56 M is not the number I was looking for. If you add up all the row totals the grand total should be $89,389,186. 

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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