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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
QooT
Frequent Visitor

Sum only if latest value is not blank

Hi There,

I need help with DAX taht will show totals correctly.
In Totals I only want to have a sum of elements where last month is not blank.
Sample Table:

GROUPIDMonthValue
A111
A122
A211
A222
A233
B311
B322
B331
B411
B422


And the desired result in Matrix should be like this:

GROUPIDMonth 1Month 2Month 3Total 
A TOTAL 24366 Because For ID 1 lastMonth is blank so we only sum ID 2
 112 00 Because Last month is Blank
 21236Last Month ist not blank so we sum all months for that ID
B TOTAL 22144 becasue For ID 4 last Month is blank so we only sum ID 3
 31214Last Month ist not blank so we sum all months for that ID
 41  00 Because Last month is Blank
GRAND TOTAL 46410 
2 REPLIES 2
ThxAlot
Super User
Super User

 

Weird Sum = 
SUMX(
    VALUES( 'Sample'[ID] ),
    CALCULATE(
        IF(
            MAX( 'Sample'[Month] )
                <> CALCULATE( MAX( 'Sample'[Month] ), REMOVEFILTERS( 'Sample'[ID] ) ),
            0,
            SUM( 'Sample'[Value] )
        )
    )
)

 

ThxAlot_1-1697210848763.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



sjoerdvn
Super User
Super User

sjoerdvn_0-1697209728778.png

Total = IF(HASONEVALUE('Table'[Month]), SUM('Table'[Value]),
    VAR last_month=CALCULATE(MAX('Table'[Month]),ALL())
    VAR last_ids = CALCULATETABLE(VALUES('Table'[ID]), ALL(), 'Table'[Month]=last_month)
    RETURN CALCULATE(SUM('Table'[Value]), KEEPFILTERS(last_ids)) + 0
)

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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