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! Learn more

Reply
zemagon
Frequent Visitor

How can I change the result of this formula?

Hi All,

 

     I need your help, If I want to subtract now, the result would be, for example, 10+9, and I would like to get the result 10-9.

 

Subtotal = VAR CurrentRowValue =
CALCULATE(
    SUM(Sheet4[Value]),
    FILTER(
        Sheet4,
        Sheet4[DuplicateCheck] = EARLIER(Sheet4[DuplicateCheck])
        && Sheet4[NewTimeColumn] = EARLIER(Sheet4[NewTimeColumn])
    )
)
RETURN
    CurrentRowValue

 

from this :

zemagon_0-1707968279436.png

 

To This :

zemagon_1-1707968308789.png

Best Regards,

Gon

 

2 ACCEPTED SOLUTIONS

@zemagon 

 

Daniel29195_0-1707982028094.png

 

 

use the measure below : 

Measure 2 = 
 var t =  MAX('Table'[time])
 var failed_step  = SELECTEDVALUE('Table'[Fail Step])


var ds = 
CALCULATETABLE(
    SUMMARIZE(
        'Table',
        'Table'[Fail Step],'Table'[time],'Table'[value]),
    'Table'[time]<=t,
    'Table'[Fail Step] = failed_step
)


var ds_w = 
    WINDOW(
        0,abs,1,REL,
        ds,
        ORDERBY('Table'[time], DESC),
        PARTITIONBY('Table'[Fail Step])
    )
    

var cacl     = 

    
SUMX(
    ds_w,
    SWITCH(
        TRUE(),
        'Table'[time] = t ,'Table'[value],
    'Table'[value] * -1 
    )
)

return cacl

 

 

let me know if this helps .

 

 

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

View solution in original post

Hi,

Use these calculated column formulas

Latest value prior to the one in the current row = LOOKUPVALUE(Data[value],Data[time],CALCULATE(MAX(Data[time]),FILTER(Data,Data[Fail Step]=EARLIER(Data[Fail Step])&&Data[time]<EARLIER(Data[time]))),Data[Fail Step],Data[Fail Step])
Diff = Data[value]-Data[Latest value prior to the one in the current row]

Hope this helps.

Ashish_Mathur_0-1707982116302.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

7 REPLIES 7
Daniel29195
Super User
Super User

@zemagon 

sorry, but i didnt get what you want to achieve ? 

can you please illustrate it with an example ? 
like what is the logic for the calculation you want to get ? 

 

Dear @Daniel29195 
     I apologize for the insufficient information. I have data as shown below. I have data for 4 time ranges: (1AM, 7AM), (1PM, 8PM). These are Fail Step data for machine pairing operations. Since the 7AM data duplicates the 1AM data (and likewise for 1PM, 8PM), I want to subtract the values of matching time pairs with the same Fail Step. The formula I have written yields a sum instead of a subtraction. Do you have any suggestions on how I can achieve this?

zemagon_0-1707967895445.png

If you need any additional information, please let me know.
Best Regards,
Gon

 

@zemagon 

 

Daniel29195_0-1707982028094.png

 

 

use the measure below : 

Measure 2 = 
 var t =  MAX('Table'[time])
 var failed_step  = SELECTEDVALUE('Table'[Fail Step])


var ds = 
CALCULATETABLE(
    SUMMARIZE(
        'Table',
        'Table'[Fail Step],'Table'[time],'Table'[value]),
    'Table'[time]<=t,
    'Table'[Fail Step] = failed_step
)


var ds_w = 
    WINDOW(
        0,abs,1,REL,
        ds,
        ORDERBY('Table'[time], DESC),
        PARTITIONBY('Table'[Fail Step])
    )
    

var cacl     = 

    
SUMX(
    ds_w,
    SWITCH(
        TRUE(),
        'Table'[time] = t ,'Table'[value],
    'Table'[value] * -1 
    )
)

return cacl

 

 

let me know if this helps .

 

 

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

Hi,

For this new table that you have shared, show the expected result in another column very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Dear @Ashish_Mathur 


Here is the table of data with the columns Result I need. Thank you for your feedback.

timeFail StepvalueDuplicateCheckAnswer
1amCheck Flow Rate10110
1amEnable Bypass505
1amGet Calibration Data15015
7amCheck Flow Rate1818
7amReset Setup303
1pmRun10min616
1pmEnable Bypass808
8pmBuckmode707
8pmRun10min711

 

Best Regards,

Gon

 

Hi,

Use these calculated column formulas

Latest value prior to the one in the current row = LOOKUPVALUE(Data[value],Data[time],CALCULATE(MAX(Data[time]),FILTER(Data,Data[Fail Step]=EARLIER(Data[Fail Step])&&Data[time]<EARLIER(Data[time]))),Data[Fail Step],Data[Fail Step])
Diff = Data[value]-Data[Latest value prior to the one in the current row]

Hope this helps.

Ashish_Mathur_0-1707982116302.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Share data in a format that can be pasted in an MS Excel file.  An image does not help.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors