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

The Fabric community is upgrading! Read all of the details including the timeline and what you can expect. Learn more

Reply
Tito
Helper IV
Helper IV

MAX-Formula

Hello,

I have a problem with the MAX formula. In my example, I want to calculate a sum of sales with maximum of date only for group A. And for group B I calculate the sum of sales without the maximum. Finally I calculate the total sum (MaxSalesGroupA + SalesGroupB). In the example, if I select group A from the filter, the name "Max" has 4000, but this is not correct. In this case the name "Max" does not need to be in the matrix anymore.
I actually have a big file, but I added an example in the attachment (see picture of Excel).

Best regards


Raw data (Excel):

MAX-Rohdaten.PNG

Result:

PBI_Sales MAX Group A.PNG

DAX:

DAX-Sum Sales current.PNG

1 ACCEPTED SOLUTION
Tito
Helper IV
Helper IV

Hello,

I have solved the problem with the following DAX function.

Thank you very much for your support. 

MAX-DAX.PNG

View solution in original post

11 REPLIES 11
Tito
Helper IV
Helper IV

Hello,

I have solved the problem with the following DAX function.

Thank you very much for your support. 

MAX-DAX.PNG

Dangar332
Resident Rockstar
Resident Rockstar

hi, @Tito 

 

try below

sum sales current 2 = 
var a = CALCULATE(MAX(tebelle1[date]),ALLEXCEPT(tebelle1,tebelle1[group]))
var b = SUMX(FILTER(tebelle1,tebelle1[date]=a),tebelle1[sales])
var c = SUMX(FILTER(tebelle1,tebelle1[group]="b"),tebelle1[sales])
return 
b+c

Thank you for your answer.
I have tried the formula, but the calculation is not correct.

Dangar332
Resident Rockstar
Resident Rockstar

hi, @Tito 

 

try below code 

sum sales current 2 = 
var a =  CALCULATE(
            MAX(tebelle1[sales]),
            ALLEXCEPT(tebelle1,tebelle1[date]),
            KEEPFILTERS(tebelle1[group]="a")
                   )

var b = CALCULATE(
            sum(tebelle1[sales]),
            tebelle1[sales]=a
                  )

var c = CALCULATE(
            sum(tebelle1[sales]),
             KEEPFILTERS(tebelle1[group]="b")
                  )

return 
  b+c

 

Dangar332_0-1698595450966.png

 

Thank you for your help.

But when I add the date to the matrix, it doesn't show correctly.

MAX2.PNG

Dangar332
Resident Rockstar
Resident Rockstar

hi, @Tito 

 

if you want only those name which have sales with max date and want to show only max date and name related to those date then change order of column in visual

 

like below  with same result measure.

Dangar332_0-1698602659525.png

 

Dangar332
Resident Rockstar
Resident Rockstar

Hi, @Tito 

 

try below 

 

 

 

result = 
var a = CALCULATE(MAX(tebelle1[date]),KEEPFILTERS(tebelle1[group]="a"),ALLEXCEPT(tebelle1,tebelle1[group]))
var b = CALCULATE(SUM(tebelle1[sales]),FILTER(tebelle1,tebelle1[date]=a))
var c = CALCULATE(SUM(tebelle1[sales]),KEEPFILTERS(tebelle1[group]="b"))
return 
b+c

 

 

 

 

 

Dangar332_0-1698603590504.png

 

Thanks for the further help.

When I select "A" or "B" from the filter, the correct result comes up. But if I do not use the filters, the correct result does not come.

Result.PNG

Hi @Tito 

Would something like this help?

Sum Sales current 2 = 
VAR MaxSalesGroupA =
    CALCULATE (
        SUM ( Tabelle1[Sales] ),
        Tabelle1[Date] = MAX ( Tabelle1[Date] ),
        KEEPFILTERS ( Tabelle1 ),
        Tabelle1[Group] = "A"
    )
VAR SalesGroupB =
    CALCULATE (
        SUM ( Tabelle1[Sales] ),
        KEEPFILTERS ( Tabelle1 ),
        Tabelle1[Group] = "B"
    )
RETURN
    MaxSalesGroupA + SalesGroupB

Tito --- MAX formula.pbix



Proud to be a Super User!

daxformatter.com makes life EASIER!

Thank you for your answer.

I have tried this before, but it did not work.

Thank you

Dangar332
Resident Rockstar
Resident Rockstar

Hi, @Tito 

 

Means You want William(5000) and Luca(5000) for group A ?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.