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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
samil01
Frequent Visitor

Subtract Negative Values ​​From Positive Values

Hi everyone,

 

Hopefully someone can help me out with my issue here, I have a condition for a measure. If sales type equal to 1 then i do want to do nothing but if its not equal to 1 i want to value minus.

 

Calculated Gross Amount = 
VAR SelectedSalesType = SELECTEDVALUE(dwh_invoice_header[sales_type])
VAR GrossAmount = SUM(dwh_invoice_header[gross_amount])
RETURN
    IF(SelectedSalesType = 1, GrossAmount, -GrossAmount)

 

This code works for rows but sub total is wrong.

 

rapor.png

 

How can i fix it?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @samil01 

You can try the following measure

Total =
IF (
    [Calculated Gross Amount] > 0,
    SUMX (
        FILTER ( dwh_invoice_header, [Calculated Gross Amount] > 0 ),
        [Calculated Gross Amount]
    ),
    [Calculated Gross Amount]
)

vxinruzhumsft_0-1690857546956.png

 

Best Regards!

Yolo Zhu

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

4 REPLIES 4
Anonymous
Not applicable

Hi @samil01 

You can try the following measure

Total =
IF (
    [Calculated Gross Amount] > 0,
    SUMX (
        FILTER ( dwh_invoice_header, [Calculated Gross Amount] > 0 ),
        [Calculated Gross Amount]
    ),
    [Calculated Gross Amount]
)

vxinruzhumsft_0-1690857546956.png

 

Best Regards!

Yolo Zhu

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

mlsx4
Memorable Member
Memorable Member

Hi @samil01 

 

You will need a SUMX(Table, [calculated gross amount])

samil01
Frequent Visitor

Thanks for the answer,

 

I try to add SUMX and a write an other DAX something like this,

 

 

Total = SUMX(dwh_invoice_header,[Calculated Gross Amount])

 

 

and it kind of works but the problem now is subtracts negative values ​​twice

 

rapor.png

 

what i am doing wrong?

mlsx4
Memorable Member
Memorable Member

Hi @samil01 

 

I will do the following:

CalculatedGrossSales= SUM('Table'[gross_amount])


And now:

Total = SUMX('Table', IF('Table'[Sales_type] = 1, -[CalculatedGrossSales], [CalculatedGrossSales]))

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.