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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Trying to include a value twice once positive and once negative.

Hi Guys,

 

I have a sample data which has first 3 columns (A-C) from raw data and one column D is calculated based on if statement. 

 

ABCD
Inv_noCodeAmountBucket
0003655ABC666APPLE
0003656DEF213APPLE
0003657GHI10PEAR
0003655JKL58BANANA
0003656ABC533APPLE
0003657DEF94APPLE
0003655GHI156PEAR
0003656ABC222APPLE
0003657DEF234APPLE
0003655GHI247PEAR
0003656ABC259APPLE
0003657DEF272APPLE
0003655GHI285PEAR
0003656JKL297BANANA
0003657ABC310APPLE
0003655DEF323APPLE
0003656GHI335PEAR
0003657JKL10BANANA
0003655ABC58APPLE
0003656DEF533APPLE
0003657GHI94PEAR
0003655JKL247BANANA
0003656ABC259APPLE
0003657DEF272APPLE
0003655GHI156PEAR
0003656JKL222BANANA
0003657ABC234APPLE
0003655DEF285APPLE
0003656GHI297PEAR
0003657JKL310BANANA
0003655ABC323APPLE
0003656DEF10APPLE
0003657GHI58PEAR
0003655JKL533BANANA
0003656ABC94APPLE
0003657DEF247APPLE

 

Column D is =IF(OR(C4="ABC",C4="DEF"),"APPLE",IF(C4="GHI","PEAR","BANANA"))

 

I have summarized the above data based on bucket(Column D). 

 

APPLE$5,440
BANANA$1,677
PEAR$1,638

 

What i am trying to do is: to include code "GHI" and its values in Bucket "APPLE" as well but with negative value. 

 

Amount based on codes are: 

ABC $                  2,958
DEF $                  2,482
GHI $                  1,638
JKL $                  1,677

 

So We have to take out $1,638 code "GHI" value from bucket "APPLE".

 

New summary table should look like this.

 

APPLE $                  3,802
BANANA $                  1,677
PEAR $                  1,638

 

We are doing this to reconcile the financial numbers for P&L statement. The above data set is hypothetical and has nothing to do with any real data.

 

Need help urgently.

 

Thanks

 

RM.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Based on your description, you can create a measure as follows.

sum_negative value = 

var x1=SUMX(FILTER(ALL('Table'),[Bucket]=SELECTEDVALUE('Table'[Bucket])),[Amount])

var x2=SUMX(FILTER(ALL('Table'),[Code]="GHI"),[Amount])

return

IF(MAX('Table'[Bucket])="APPLE",x1-x2,x1)

Result:

v-yuaj-msft_0-1616657488751.png

Hope that's what you were looking for.

Best Regards,

Yuna

 

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 @Anonymous ,

 

Based on your description, you can create a measure as follows.

sum_negative value = 

var x1=SUMX(FILTER(ALL('Table'),[Bucket]=SELECTEDVALUE('Table'[Bucket])),[Amount])

var x2=SUMX(FILTER(ALL('Table'),[Code]="GHI"),[Amount])

return

IF(MAX('Table'[Bucket])="APPLE",x1-x2,x1)

Result:

v-yuaj-msft_0-1616657488751.png

Hope that's what you were looking for.

Best Regards,

Yuna

 

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

 

sayaliredij
Solution Sage
Solution Sage

You can create an amount measure with the following formula. 

 

SUMAMOUNT = SUM(data[Amount]) - IF(SELECTEDVALUE(data[Bucket]) = "Apple",calculate(SUM(data[Amount]),FILTER(ALL(data),data[Code] = "GHI")))




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

Proud to be a Super User!




selimovd
Super User
Super User

Hey @Anonymous ,

 

you can do that in 2 steps.

First you need to create the column:

 

 

 

D =
SWITCH(
    TRUE(),
    myTable[Code] = "ABC" || myTable[Code] = "DEF", "APPLE",
    myTable[Code] = "GHI", "PEAR",
    "BANANA"
)

 

 

 

Then you have to do the measure for the calculation:

 

MyMeasure =
VAR vTable =
    ADDCOLUMNS(
        VALUES( 'myTable'[Bucket] ),
        "SUM",
            IF(
                'myTable'[Bucket] = "APPLE",
                CALCULATE( SUM( 'myTable'[Amount] ), 'myTable'[Bucket] = "APPLE" ) - CALCULATE( SUM( 'myTable'[Amount] ), 'myTable'[Bucket] = "PEAR" ),
                CALCULATE( SUM( 'myTable'[Amount] ) )
            )
    )
VAR result =
    SUMX( vTable, [SUM] )
RETURN
    result

 

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 
amitchandak
Super User
Super User

@Anonymous , create a new table code where you have GHI in both bucket with multiple 1, and -1. same way multiple 1 for other.

Join both tables on code and try this measure

 

 

Code,Bucket , multiple


sumx(Table, Table[Amount]*related(code[multiple])) or

 

or

 

sumx(Table, Table[Amount]*maxx(relatedtable(code),[multiple]))

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors