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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Adamkowalsky92
Frequent Visitor

Incorrect SUM

Hey, I need help with a simple formula. At first glance dax I wrote it is simple and in the lines it works correctly however the sum no longer match.

The formula is supposed to search for the max date with the data and subtract the previous day, but since the lines have different max dates, I want the sum of these differences, not the total for example 05.02 - 04.02

As in the image below from the green values, the red values should be subtracted. The expected result for the total is 55, with -125 received, for obvious reasons.



Adamkowalsky92_0-1738820181649.png

Thanks for help

1 ACCEPTED SOLUTION
Adamkowalsky92
Frequent Visitor

I resolves problem myself ny using

SUMX(
    SUMMERIZE(
              Sales,Sales[Client],"Sum",CALCULATE(SUM(Sales[Value]),Sales[Date]=MAX(Sales[Date]))),Sum)

_


SUMX(
    SUMMERIZE(
              Sales,Sales[Client],"Sum",CALCULATE(SUM(Sales[Value]),Sales[Date]=MAX(Sales[Date])-1)),Sum)

 

View solution in original post

6 REPLIES 6
Adamkowalsky92
Frequent Visitor

I resolves problem myself ny using

SUMX(
    SUMMERIZE(
              Sales,Sales[Client],"Sum",CALCULATE(SUM(Sales[Value]),Sales[Date]=MAX(Sales[Date]))),Sum)

_


SUMX(
    SUMMERIZE(
              Sales,Sales[Client],"Sum",CALCULATE(SUM(Sales[Value]),Sales[Date]=MAX(Sales[Date])-1)),Sum)

 

bhanu_gautam
Super User
Super User

@Adamkowalsky92 , Can you share formula which you have used




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Adamkowalsky92_0-1738827479342.png

 
Parameter define how much days i want back

@Adamkowalsky92 Try using

 

dax
VAR maxday = MAX(Sales[Day])
VAR beforeday = CALCULATE(MAX(Sales[Day]), Sales[Day] < maxday)
VAR sales = CALCULATE(SUM(Sales[Value]), Calendar[Date] = maxday)
VAR salesbefore = CALCULATE(SUM(Sales[Value]), Calendar[Date] = beforeday)
RETURN
SUMX(
VALUES(Sales[Day]),
sales - salesbefore
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Unfortunately, this is not a suitable solution:

1. you have not added a parameter option that defines the value by a certain number of days
2. I want the sum of only one day, not all earlier than max date

Anonymous
Not applicable

Hi @Adamkowalsky92 ,
I tried to reproduce your visual object, but was unsuccessful. However, I think this problem can be solved quickly. To better help you solve the problem, could you provide some example pbix? Thank you very much for your cooperation!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.