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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Analitika
Post Prodigy
Post Prodigy

MAX return wrong results

I have Table1

OpNr  | ApNr | Sum | Date

123 | 456 | 300 | 2019-07-17
123 | 856 | 50 | 2019-08-07

 

Expected result

ApNr | TotalSumByOpNr | MaxDate
456 | 350 | 2019-08-07
856 | 350 | 2019-08-07

Total | 350 | empty (show no dates)

 

I use

TotalSumByOpNr  = SUMX(VALUES(Table1[OpNr]), CALCULATE(MAX(Table1[Sum])))
MaxDate = MAX(Table1[Date])



Why max return wrong result

Measure = MAX(Table1[Date])

 

Analitika_0-1597301519889.png

expected 2019-08-07 all

How to dermine dependants by which max function filter values?

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Analitika 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table1:

a1.png

 

You may create two measures as below.

TotalSumByOpNr = 
var tab = 
SUMMARIZE(
    Table1,
    Table1[ApNr],
    "Result1",
    var _opnr = SELECTEDVALUE(Table1[OpNr])
    return
    CALCULATE(
        SUM(Table1[Sum]),
        FILTER(
            ALL(Table1),
            Table1[OpNr]=_opnr
        )
    )
)
return
MAXX(
    tab,
    [Result1]
)

 

MaxDate = 
var tab = 
SUMMARIZE(
    Table1,
    Table1[ApNr],
    "Result2",
    var _opnr = SELECTEDVALUE(Table1[OpNr])
    return
    CALCULATE(
        MAX(Table1[Date]),
        FILTER(
            ALL(Table1),
            Table1[OpNr]=_opnr
        )
    )
)
return
IF(
    ISFILTERED(Table1[ApNr]),
    MAXX(
        tab,
        [Result2]
    )
)

 

Result:

a2.png

 

Best Regards

Allan

 

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

View solution in original post

7 REPLIES 7
v-alq-msft
Community Support
Community Support

Hi, @Analitika 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table1:

a1.png

 

You may create two measures as below.

TotalSumByOpNr = 
var tab = 
SUMMARIZE(
    Table1,
    Table1[ApNr],
    "Result1",
    var _opnr = SELECTEDVALUE(Table1[OpNr])
    return
    CALCULATE(
        SUM(Table1[Sum]),
        FILTER(
            ALL(Table1),
            Table1[OpNr]=_opnr
        )
    )
)
return
MAXX(
    tab,
    [Result1]
)

 

MaxDate = 
var tab = 
SUMMARIZE(
    Table1,
    Table1[ApNr],
    "Result2",
    var _opnr = SELECTEDVALUE(Table1[OpNr])
    return
    CALCULATE(
        MAX(Table1[Date]),
        FILTER(
            ALL(Table1),
            Table1[OpNr]=_opnr
        )
    )
)
return
IF(
    ISFILTERED(Table1[ApNr]),
    MAXX(
        tab,
        [Result2]
    )
)

 

Result:

a2.png

 

Best Regards

Allan

 

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

vanessafvg
Super User
Super User

please can you give more information, its hard to understand what you are doing, what result is it returning, how are you running this calculation, do you have some data to share?




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




FarhanAhmed
Community Champion
Community Champion

MAX is evaluating for each row, if you want to exlcude row context in the formula you can use something like this

 

_MAX Date = CALCULATE (Max (Table[date]),All(Table))

 







Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




amitchandak
Super User
Super User

@Analitika , The information you have provided is not making the problem clear to me. Can you please explain with an example.
Max seems to work for Grand total.  do you need only one row

 

Same value in all column

Measure = calculate(MAX(Table1[Date]), allselected(Table1))

or

Measure = calculate(MAX(Table1[Date]), all(Table1))
Appreciate your Kudos.


Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I have Table1

OpNr  | ApNr | Sum | Date

123 | 456 | 300 | 2019-07-17
123 | 856 | 50 | 2019-08-07

 

Expected result

ApNr | TotalSumByOpNr | MaxDate
456 | 350 | 2019-08-07
856 | 350 | 2019-08-07

Total | 350 | empty (show no dates)

 

I use

TotalSumByOpNr  = SUMX(VALUES(Table1[OpNr]), CALCULATE(MAX(Table1[Sum])))
MaxDate = MAX(Table1[Date])

 

@Analitika , add these columns with OpNr in your visual

 

calculate(lastnonblankvalue(Table[Date], Sum(Table[Sum])), allexcept(Table[OpNr]))
calculate(max(Table[Date]), allexcept(Table[OpNr]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

It is not working, as produce dublicates

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.