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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply

Can't get DAX Total / Sub Total to work!

Here is my measure:

Cash Balance [GBP]:=VAR CorrectTable =
ADDCOLUMNS (
GROUPBY (
Projected_Cash_Balances,
Projected_Cash_Balances[Country],
Projected_Cash_Balances[Dates]
),
"Last Balance [GBP]", SUMX (
FILTER (
Projected_Cash_Balances,
[Index] = MAX ( [Index] )
&& LASTDATE ( Projected_Cash_Balances[Dates] )
),
[Balance [GBP]]]
)
)
RETURN
AVERAGEX ( CorrectTable, AVERAGE ( [Last Balance [GBP]]] ) )

 

Pic2.PNGPic1.PNG

Attached is my input table, and a pivot table. The cell highlighted in yellow is wrong... : (  (it should be 79,723)

 

Thanks in advance,

 

Sachin

 

 

1 ACCEPTED SOLUTION

ok, problem now solved

 

VAR CorrectTable =
    ADDCOLUMNS (
        GROUPBY (
            Projected_Cash_Balances,
            Projected_Cash_Balances[Country],
            Projected_Cash_Balances[Dates]
        ),
        "Last Balance [GBP]"AVERAGEX (
            FILTER (
                Projected_Cash_Balances,
                [Index]
                    MAXX (
                        FILTER (
                            Projected_Cash_Balances,
                            [Country] = EARLIER ( [Country] )
                                && [Dates] = MAX ( [Dates] )
                        ),
                        [Index]
                    )
            ),
            [Balance [GBP]]]
        )
    )
RETURN
    SUMX (
        FILTER ( CorrectTable, [Dates] = MAX ( [Dates] ) ),
        [Last Balance [GBP]]]
    )

 

Pic4.PNG

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the suggested help.

 

I read through both links, but am still struggling with my specific problem.

 

The totals are not always wrong. Just wrong on some days....

 

Pic3.PNG

 

With updated DAX below (but it is still not working....)  = [

 

Cash Balance [GBP]:=VAR CorrectTable =
ADDCOLUMNS (
GROUPBY (
Projected_Cash_Balances,
Projected_Cash_Balances[Country],
Projected_Cash_Balances[Dates]
),
"Last Balance [GBP]", AVERAGEX (
FILTER (
Projected_Cash_Balances,
[Index] = MAX ( [Index] )
&& [Country] = EARLIER([Country])
&& [Dates] = MAX([Dates])),
[Balance [GBP]]]
)
)
RETURN
SUMX ( FILTER(CorrectTable, [Dates] = MAX([Dates] )), [Last Balance [GBP]]])

ok, problem now solved

 

VAR CorrectTable =
    ADDCOLUMNS (
        GROUPBY (
            Projected_Cash_Balances,
            Projected_Cash_Balances[Country],
            Projected_Cash_Balances[Dates]
        ),
        "Last Balance [GBP]"AVERAGEX (
            FILTER (
                Projected_Cash_Balances,
                [Index]
                    MAXX (
                        FILTER (
                            Projected_Cash_Balances,
                            [Country] = EARLIER ( [Country] )
                                && [Dates] = MAX ( [Dates] )
                        ),
                        [Index]
                    )
            ),
            [Balance [GBP]]]
        )
    )
RETURN
    SUMX (
        FILTER ( CorrectTable, [Dates] = MAX ( [Dates] ) ),
        [Last Balance [GBP]]]
    )

 

Pic4.PNG

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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