Arithmetic Operations in DAX: Calculate Profit with Inclusive and Exclusive Tax
In this article, we will learn how to perform arithmetic operations in DAX
using variables, calculate profit with inclusive and exclusive tax,
and handle zero-division errors using the DIVIDE function.
We will use three practical scenarios to understand how DAX performs calculations
on individual rows and how variables can simplify query logic.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist
What Are Arithmetic Operations in DAX?
Arithmetic operations allow us to perform mathematical calculations on numeric values
in DAX. These operations are useful for calculating sales, tax, profit, discounts,
margins, and other business metrics.
The main arithmetic operators are:
| Operator | Operation | Example |
|---|---|---|
| + | Addition | 100 + 50 = 150 |
| – | Subtraction | 100 – 50 = 50 |
| * | Multiplication | 100 * 2 = 200 |
| / | Division | 100 / 2 = 50 |
In this example, we will use arithmetic operations to calculate
profit from sales amounts and product costs.
Understanding the Tax Variable
Query
// Arithmetic Operations
DEFINE
VAR Tax = 18
Step-by-step explanation
Step 1: DEFINE
DEFINE is used to declare variables that can be used
in one or more DAX queries.
Step 2: VAR Tax = 18
This creates a variable named Tax and assigns it the value
18.
The value 18 represents an 18% tax rate.
To use it in a calculation, we convert it into a decimal by dividing it by 100.
Tax / 100
18 / 100 = 0.18
A percentage such as 18 must be converted to
0.18 when used in a mathematical calculation.
1. Calculate Profit Using Inclusive of Tax
In this scenario, the Sales Amount already includes tax.
Therefore, we first calculate the Base Amount by removing
the tax component from the sales amount.
Query
// Scenario 01: Calculate Profit using Inclusive of Tax
EVALUATE
ADDCOLUMNS(
Sales,
"Base Amount", Sales[Sales Amount] / (1 + (Tax/100)),
"Profit", Sales[Sales Amount] / (1 + (Tax/100)) - Sales[Total Product Cost]
)
Step-by-step explanation
Step 1: EVALUATE
EVALUATE returns the result of the table expression.
In this case, the result is a table containing the original Sales columns
and the newly calculated columns.
Step 2: ADDCOLUMNS
ADDCOLUMNS adds calculated columns to an existing table.
Here, the source table is Sales.
Step 3: Calculate the Base Amount
The expression:
Sales[Sales Amount] / (1 + (Tax/100))
First, we convert the tax percentage into a decimal:
Tax / 100
18 / 100 = 0.18
Next, we add 1 to the tax rate:
1 + 0.18 = 1.18
Finally, we divide the inclusive sales amount by 1.18
to calculate the amount before tax.
Step 4: Calculate Profit
The expression:
Sales[Sales Amount] / (1 + (Tax/100)) - Sales[Total Product Cost]
This formula first calculates the Base Amount and then subtracts
Total Product Cost.
Profit = Base Amount – Total Product Cost
Example calculation
Suppose a sales amount is 1,180 and the total product cost is
700.
| Calculation | Result |
|---|---|
| Sales Amount | 1,180 |
| Tax Rate | 18% |
| Base Amount = 1,180 / 1.18 | 1,000 |
| Total Product Cost | 700 |
| Profit = 1,000 – 700 | 300 |
What will you get?
The query returns the original Sales table along with two new columns:
| Sales Amount | Total Product Cost | Base Amount | Profit |
|---|---|---|---|
| 1,180 | 700 | 1,000 | 300 |
| 590 | 350 | 500 | 150 |
The example above is only for illustration. Your actual result will contain
the data available in your Sales table.
When the sales amount already includes tax, divide it by
1 + Tax Rate to calculate the base amount before tax.
2. Calculate Profit Using Exclusive Tax
In this scenario, we calculate the tax separately from the sales amount.
The sales amount is treated as the amount before tax.
Query
// Scenario 02: Calculate Profit using Exclusive Tax
EVALUATE
ADDCOLUMNS(
Sales,
"Exclusive Tax", Sales[Sales Amount] * (Tax/100),
"Profit", Sales[Sales Amount] - Sales[Total Product Cost]
)
Step-by-step explanation
Step 1: EVALUATE
Returns the result of the table expression.
Step 2: ADDCOLUMNS
Adds calculated columns to the Sales table.
Step 3: Calculate Exclusive Tax
The expression:
Sales[Sales Amount] * (Tax/100)
First, we convert the tax percentage into a decimal:
Tax / 100
18 / 100 = 0.18
Next, we multiply the sales amount by the tax rate.
Exclusive Tax = Sales Amount × Tax Rate
Step 4: Calculate Profit
The expression:
Sales[Sales Amount] - Sales[Total Product Cost]
This calculates profit by subtracting the total product cost from the sales amount.
Profit = Sales Amount – Total Product Cost
Example calculation
Suppose a sales amount is 1,000 and the total product cost is
700.
| Calculation | Result |
|---|---|
| Sales Amount | 1,000 |
| Tax Rate | 18% |
| Exclusive Tax = 1,000 × 0.18 | 180 |
| Total Product Cost | 700 |
| Profit = 1,000 – 700 | 300 |
What will you get?
The query returns the original Sales table along with two new columns:
| Sales Amount | Total Product Cost | Exclusive Tax | Profit |
|---|---|---|---|
| 1,000 | 700 | 180 | 300 |
| 500 | 350 | 90 | 150 |
The example above is only for illustration. Your actual result will contain
the data available in your Sales table.
When the sales amount is before tax, multiply it by the tax rate
to calculate the tax amount separately.
3. Handle Zero Division Errors Using DIVIDE
Division by zero can cause errors in calculations. DAX provides the
DIVIDE function to handle this situation safely.
Query
// Scenario 03: Zero Division Error
EVALUATE
VAR TotalSales = 1000
VAR TotalTax = 0
VAR SalesTaxRatio = DIVIDE(TotalSales, TotalTax, 0)
RETURN
ROW(
"Sales Tax Ratio", SalesTaxRatio
)
Step-by-step explanation
Step 1: EVALUATE
Returns the result of the table expression.
Step 2: VAR TotalSales = 1000
Creates a variable named TotalSales with the value
1000.
Step 3: VAR TotalTax = 0
Creates a variable named TotalTax with the value
0.
Step 4: VAR SalesTaxRatio = DIVIDE(TotalSales, TotalTax, 0)
The DIVIDE function calculates the ratio safely.
DIVIDE(<Numerator>, <Denominator>, <Alternate Result>)
In this example:
| Argument | Value | Meaning |
|---|---|---|
| Numerator | TotalSales | 1000 |
| Denominator | TotalTax | 0 |
| Alternate Result | 0 | Returned when division is not possible |
Since the denominator is 0, DAX returns the alternate result,
which is 0.
Step 5: RETURN
RETURN specifies the expression that should be returned
after the variables are defined.
Step 6: ROW
ROW creates a single-row table containing the calculated value.
ROW(
"Sales Tax Ratio", SalesTaxRatio
)
What will you get?
| Sales Tax Ratio |
|---|
| 0 |
Use DIVIDE when you need to handle possible
zero-division situations safely.
Understanding the Difference
| Scenario | Formula | Purpose |
|---|---|---|
| Inclusive Tax | Sales Amount / (1 + Tax Rate) | Calculate the base amount before tax |
| Exclusive Tax | Sales Amount × Tax Rate | Calculate tax separately |
| Profit | Sales Amount – Total Product Cost | Calculate the difference between sales and cost |
| Zero Division | DIVIDE(Numerator, Denominator, Alternate Result) | Return a safe result when division is not possible |
Important Notes
1. Inclusive and exclusive tax are different calculations
Inclusive tax means the sales amount already contains tax.
Exclusive tax means the tax is calculated separately from the sales amount.
2. Arithmetic operations follow mathematical rules
DAX uses standard arithmetic operators such as
+, –, *, and /.
3. DIVIDE is useful for safe division
When the denominator may be zero, use DIVIDE with an
alternate result to avoid invalid calculations.
4. Variables make calculations easier to understand
Variables such as Tax, TotalSales,
and TotalTax make the query easier to read and maintain.
5. ADDCOLUMNS creates calculated columns
ADDCOLUMNS returns a new table expression with the
calculated columns added to the original table.
📝 Practice Exercise
Try writing a DAX query to calculate the following for each row in the
Sales table:
- Base Amount using 18% inclusive tax
- Exclusive Tax using 18% tax
- Profit using Sales Amount minus Total Product Cost
Also, try using DIVIDE to calculate a ratio safely
when the denominator is zero.
Conclusion
In this article, we learned how to perform arithmetic operations in DAX
using variables and calculated columns.
- How to calculate the base amount from an inclusive tax amount.
- How to calculate exclusive tax separately from the sales amount.
- How to calculate profit using sales amount and product cost.
- How to handle zero-division errors using the DIVIDE function.
- How to use ADDCOLUMNS to create calculated columns.
These arithmetic operations are useful building blocks for creating
financial calculations, sales analysis, and business metrics in DAX.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist