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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
EmiliaB_123
Helper II
Helper II

Subtraction Formula doesn´t Work

Hi everyone,

I am creating a simple subtraction formula in the Data Query and unfortunately the result is not correct. I think this is due to the "null" values. It only shows result values of the formula when both columns are filled with figures. Those lines are all related to one project. So what I actually need is the sum of one column minus the sum of the second column. Is there a formula that can show this? Please consider that the values are per Project and Period. So it would need to consider the sum values per project and period.

Thank you!

 

EmiliaB_123_0-1616571524144.png

 

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

Hi @EmiliaB_123 ,

 

Please try this:

Column =
CALCULATE (
    SUM ( 'Table'[COST_ESTIMATED] ),
    ALLEXCEPT ( 'Table', 'Table'[Period], 'Table'[Project ] )
) + 0
    - CALCULATE (
        SUM ( 'Table'[COST_ACTUAL] ),
        ALLEXCEPT ( 'Table', 'Table'[Period], 'Table'[Project ] )
    ) + 0

The final output is shown below:

3.26.2.null.PNG

 

Best Regards,
Eyelyn Qin
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

12 REPLIES 12
v-eqin-msft
Community Support
Community Support

Hi @EmiliaB_123 ,

 

Please try this:

Column =
CALCULATE (
    SUM ( 'Table'[COST_ESTIMATED] ),
    ALLEXCEPT ( 'Table', 'Table'[Period], 'Table'[Project ] )
) + 0
    - CALCULATE (
        SUM ( 'Table'[COST_ACTUAL] ),
        ALLEXCEPT ( 'Table', 'Table'[Period], 'Table'[Project ] )
    ) + 0

The final output is shown below:

3.26.2.null.PNG

 

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

lovishsood1
Helper II
Helper II

Did you try replacing 'null' values with 0?

Hi @lovishsood1 , it was the first thing I tried and it didn´t work.

lovishsood1_0-1616657430533.png

are you expecting such results?

Angith_Nair
Helper V
Helper V

Hi @EmiliaB_123 ,

Lets assume this as A - B = C.

Could I please know what you want to display in C when A is null or B is null..?

Hello @Angith_Nair ,

thanks for your quick reply. That is actually a good question, if see the values then there should be also negative figures. But if we take the total of A and the total of B there should be only one figure shown as result. I understand that the nulls seem to be a problem, but can´t the system ignore them in some way?

Do you want the total of A column subtracted with the total of B column and then display that single value in every row..? If yes then you can create a calculated column in Power BI level where the code will be SUM(Table[A]) - SUM(Table[B]).

If No then assume the data like this

A             B           C

12           Null       12

Null         10         10

Is that what you needed..?

Hello @Angith_Nair ,

I tried out thir formula but it shows me the sum of all the columns. So there is always the same values shown. As I mentioned this needs to be the sum for one project and one period and not over all.

Hi @EmiliaB_123 ,

Assume the data like this

A             B           C

12           Null       12

Null         10         10

25            11         14

10            20         10

Do you want this kind of result..?

yes

Try to create calculated column with this code..

 

Column =
ABS (
    IF (
        ISBLANK ( 'Table'[A] ),
        'Table'[B],
        IF ( ISBLANK ( 'Table'[B] ), 'Table'[A], 'Table'[A] - 'Table'[B] )
    )
)

 

which will look like this..

Angith_Nair_0-1616656646659.png

 

Hi @Angith_Nair ,

yes this is what I need thanks. I will try this out and mark it as a solution if it works. Thank you very much on the quick reply!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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