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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
adraus
Frequent Visitor

Subtract two columns

I'm trying to do simple subtraction of two columns.  I'm creating a pay register.  I have a column with earnings, a column with deductions and want to subtract deductions from earnings to create a new column, net pay for each employee.

 

Earnings and deductions come from separate tables.  When I try to subtract these, it always aggregates the amounts, rather than giving me just the amount for each.

 

How do I successfully subtract?

adraus_0-1653344652290.png

 

adraus_1-1653344693324.png

 

adraus_3-1653344951516.png

 

 

 

 

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @adraus 

 

You can try the following methods.

Measure = 
SELECTEDVALUE(_GroupEarnings[_EarnAmount])-SELECTEDVALUE(_GroupDeductions[_DedAmount])
Measure 2 = 
SUM(_GroupEarnings[_EarnAmount])-SUM(_GroupDeductions[_DedAmount])

vzhangti_0-1653546778725.png

Both of these measures give the result of subtracting two columns.

 

Best Regards,

Community Support Team _Charlotte

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

View solution in original post

5 REPLIES 5
v-zhangti
Community Support
Community Support

Hi, @adraus 

 

You can try the following methods.

Measure = 
SELECTEDVALUE(_GroupEarnings[_EarnAmount])-SELECTEDVALUE(_GroupDeductions[_DedAmount])
Measure 2 = 
SUM(_GroupEarnings[_EarnAmount])-SUM(_GroupDeductions[_DedAmount])

vzhangti_0-1653546778725.png

Both of these measures give the result of subtracting two columns.

 

Best Regards,

Community Support Team _Charlotte

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

GlasBI
New Member

If the only connections are the year and payperiod (and presuming they will have same payperiod in both tables moving forward) you could try TREATAS:

 

 

Total =
VAR earnings =
    MAX ( GroupEarnings[Earnings] )
VAR deductions =
    MAX ( GroupDeductions[_DedAmount] )
RETURN
    CALCULATE (
        earnings - deductions,
        TREATAS (
            SELECTCOLUMNS (
                GroupEarnings,
                "Year", GroupEarnings[Year],
                "Payperiod", GroupEarnings[Payperiod]
            ),
            GroupDeductions[Year],
            GroupEarnings[Payperiod]
        )
    )

Nathaniel_C
Super User
Super User

Hi @adraus 

Try this.

 

 


Let me know if you have any questions.

 

Total = 

var _earn = MAX(Earnings[Earnings])

var _ded = MAX(Deductions[Deductions])

return _earn- _ded

 


If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

Nathaniel_C_0-1653352323842.png

Nathaniel_C_1-1653352758346.png

 





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

Proud to be a Super User!




I'm not having success.  The new column is showing the same invalid value all the way down.

Perhaps I missed something in the command?

 

adraus_1-1653396422328.png

 

 

Hi @adraus ,

In order to have data from two different tables they have to be linked in some fashion. 

Here is one way.

 

image.png

Please tell me, is this for a short term project or something else.  Can you share your pbix with me?

If you would share your pbix, or dummy up some values in Excel both for current and expected data. Please copy and paste them into your post, rather than doing a picture, we may be able to help you. 

Please read this post to get your question answered more quickly:

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

Nathaniel





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

Proud to be a Super User!




Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors