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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Maxakay
New Member

How to get cumulative total function with criteria

Hey,

I'm trying to get a cumul without "dates" (no TOTALYTD for example).

How to, in DAX, calculate the cumul in yellow ?

I found this code but there is a criteria missing such as colomn "Fruits"

 

 

 

 

Cumulative_Goals = 
CALCULATE (
    SUM ( DATA[Sales Goals] ),
    ALL ( DATA ),
    DATA[Month] <= EARLIER ( DATA[Month])
)

 

 

Maxakay_0-1677688901529.png

 

 

 

Thank you for your help.

7 REPLIES 7
Anonymous
Not applicable

Hi @Maxakay ,

Please have a try.

Create a measure.

measure =
CALCULATE (
    SUM ( date[salesgoals] ),
    FILTER (
        ALL ( data ),
        data[month] <= SELECTEDVALUE ( data[month] )
            && data[fruit] = SELECTEDVALUE ( data[fruit] )
    )
)

Or a column.

column =
CALCULATE (
    SUM ( date[salesgoals] ),
    FILTER (
        data,
        data[month] <= EARLIER ( data[month] )
            && data[fruit] = EARLIER ( data[fruit] )
    )
)

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

Hi,

Thanks for your help.

Maxakay_0-1680523823492.png

It works. However, is that possible to "blank" the sum when the "Sales Result" column hasn't information ?

Thanks a lot.

Mihai_Iso
Helper II
Helper II

Hi,

 

for multiple criteria

 

Cumulative Total with Criteria =

CALCULATE(
SUM(Table[Value]),
FILTER(
ALL(Table),
Table[Date] <= MAX(Table[Date])
&& Table[Column 1] = "Fruits"
&& (
CONTAINS(EARLIER(Table), Table[Column 2], "orange")
|| CONTAINS(EARLIER(Table), Table[Column 2], "apple")
|| CONTAINS(EARLIER(Table), Table[Column 2], "pears")
)
&& Table[Date] <= EARLIER(Table[Date])
)
)

 

Hi,

Thanks for the help.

I tried your formula :

Maxakay_0-1677834279595.png

It doesn't work at this point : "CONTAINS(EARLIER(Table),"

Table = DATA but i got this error : "The first argument of EARLIER/ERLIEST is not a valid column reference in the earlier row context."

I must miss something...

 

Mihai_Iso
Helper II
Helper II

Hi,

 

try this one:

-------------------------

Value = Sales Goal

Criteria=Fruits

Date=from a Calendar "Date"

---------------------------

Cumulative Total with Criteria = CALCULATE(
SUM(Table[Value]),
FILTER(
ALL(Table),
Table[Date] <= MAX(Table[Date])
&& Table[Criteria] = "Your Criteria Here"
)
)

Padycosmos
Solution Sage
Solution Sage

Hi,

 

Thanks for the link. I tried but it doesn't work.

Cumulative Goals = 
VAR Fruits =
    RANKX(
        ALL(DATA[Fruits]),
        [TOTALSales_Goals],,
        DESC,
        Dense
    )
VAR CumulativeGoals =
    Calculate(
        [TOTALSales_Goals],
        Filter(
            ALL(DATA[Fruits]),
            Fruits >= RANKX(
                ALL(DATA[Fruits]),
                [TOTALSales_Goals],,
                DESC,
                Dense
            )
        )
    )
RETURN
CumulativeGoals

Maxakay_0-1677751831424.png

I can't join a .pbx file to illustrate the problem 😕

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.