DAX DIVIDE Function
DIVIDE function is a power bi DAX math and trig functions that performs the division and returns alternate result or BLANK() on division by 0.
It returns a decimal number.
DIVIDE(<numerator>, <denominator> [,<alternateresult>])
numerator The dividend or number to divide.
denominator The divisor or number to divide by.
alternateresult It is an optional, returned when division by zero error occurred.
By default it returns blank().
Lets look at an example of using DIVIDE function in Power Bi.
Here we have a sample dataset of student score card.
Note that, You can see MaxMarks is 0 for studid 101 , and 104 in Subject English and Math respectively.
Which are taken purposely to see the DIVIDE function ability to handle the divide by zero error, and return alternate value if it is given else blank.
StudId Subject Marks Obtain MaxMarks
Lets say, you want to calculate the percentage achieved by student in each subject.
To calculate the percentage, first you need to divide Marks obtain (dividend) in subject by max marks (divisor) then multiple by the result by 100.
Lets use the DIVIDE function DAX for the division as given below.
Subject % = DIVIDE ( SUM ( StudentScoreCard[Marks Obtain] ), SUM ( StudentScoreCard[MaxMarks] ) ) * 100
After committing, the above DAX Subject %, Lets drag it into table visual as shown below.
If you want to replace blank value with zero, then you can modify above DAX and provide an alternate value, when divide by zero error occurred.
Subject % = DIVIDE ( SUM ( StudentScoreCard[Marks Obtain] ), SUM ( StudentScoreCard[MaxMarks] ) ,0 ) * 100
As you can see, Blank value is replaced with an alternate value 0.
774 total views, 1 views today