DAX DIVIDE for Excels Power Pivot, Power BI and Analysis ServicessteemCreated with Sketch.

in #excel7 years ago

The Divide Problem

 When you are working in Excel it is relatively easy to divide two numbers. You take the value from one cell, and divide it by the value in another cell.  For Example =B3/B2.  Divide is a basic mathematical operator. In Excel if you try to divide a value by zero you will get the error # DIV/0!

Power BI and Power Pivot don’t work on cell references like Excel.  They both work on columns of data.  It is very common to add a calculated column using divide. A perfect example would be on a sales table to take the profit column and divide it by sales column to get the gross profit %.

Using the mathematical divide in Power BI or Power Pivot can lead to a problem if your table of data contains a 0. You will not be returned an error. Instead you will be returned with the symbol for infinite ∞.  It is also common for people not to spot this problem.  This is because when you are working with data in Power BI or Power Pivot, only a subset of data is visible.  It is very possible that zeros are further down your data set and you have not seen them.

The DIVIDE Solution

So how can you overcome this problem in Power BI or Power Pivot? DAX is to the rescue with the DIVIDE function.  The syntax is simple =DIVIDE(Numerator, Denominator, [AlternateResult])

Let’s have a look at both the DIVIDE function and the divide operator in action. We have a table of data containing columns for Date, Invoice number, Product, Units sold, Total sales and total cost price. What we want to do is calculate the Gross profit %.

 

First we will set up a new calculated column. This column will contain the expression

= [Total Sales Price] – [Total Cost Price]

This will return the gross profit for each row in the table.  We can rename this column Profit.

  

To get the Gross Profit % we now need to divide the Profit by the Sales.  Let’s do this two ways to see the difference.  First we will look at the mathematical operator divide and then we will look at the DAX function DIVIDE().

In a new calculated column we will enter the expression

= [Profit] / [Total Sales Price]

  

If you look down the table you will find two invoices where the sales price is zero.   And look what’s happened with the calculated column for these rows.  The value returned is not error but instead ∞.

To overcome this we can use DAX DIVIDE function. 

Let’s now add a new calculated column and this time our expression will be

=DIVIDE([Profit], [Total Sales Price])

In this example we have not added the [AlternateResult] as this is optional.  By default the alternate result will be blank.

If we now edit this expression to read

=DIVIDE([Profit], [Total Sales Price],0)

This will now replace the blank with 0. 

So my advice, well it’s better to be safe than sorry right.  Always use the DAX DIVIDE function when you need to divide values.

Watch an example by video:

<iframe width="560" height="315" src="

" frameborder="0" allowfullscreen></iframe> 

If you are interested in learning more about Excel, Power BI and Data analysis and modeling with DAX then follow me.  

Want to know more about Power BI and Excel Power Tools, have a read of this post from yesterday

https://steemit.com/steemit/@paulag/analyzing-steemit-data-using-power-bi


Sort:  

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by paulag from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, and someguy123. The goal is to help Steemit grow by supporting Minnows and creating a social network. Please find us in the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you like what we're doing please upvote this comment so we can continue to build the community account that's supporting all members.

Congratulations @paulag! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

This post has received a 2.25 % upvote from @booster thanks to: @paulag.

Nice post paulag👍

thank you

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64029.44
ETH 3157.04
USDT 1.00
SBD 4.02