cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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?

1 ACCEPTED SOLUTION
Community Support

You can try the following methods.

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

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.

5 REPLIES 5
Community Support

You can try the following methods.

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

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.

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]
)
)

Super User

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

Proud to be a Super User!

Frequent Visitor

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?

Super User

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

Here is one way.

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.

Nathaniel

Proud to be a Super User!

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - July 2024

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

#### Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors