We start by storing our working number in the __num variable. Next, we calculate the maximum number that we will need to check as a divisor. This maximum number is the square root of our working number. We use the SQRT DAX function to find the square root of our working number and round this to the integer portion using INT. Any number larger than the square root of our number cannot possibly be an even divisor of our working number. This greatly reduces the number of divisors that we will need to check. We store this maximum number in the __max variable.
We then create a table from the number 2 to our __max variable in increments of 1 and add a column to this table that is the MOD function of our working number and the values in this table. The MOD function returns the remainder of a division operation, meaning, if the remainder of a division operation is 0, then the numerator is evenly divisible by the denominator. We store this final table in the __table1 variable.
For our RETURN statement, we use a SWITCH statement to first check whether the working number is 1. If so, we return FALSE, since 1 cannot be a prime number by definition. Our next check is to count all of the rows in our __table1 variable whose __mod column is 0. If there are no such rows, then COUNTROWS will return BLANK. We check to see whether the result of the COUNTROWS function is blank (ISBLANK) and, if so, we return TRUE, meaning that the working number is a prime number! Otherwise, we return FALSE, meaning the number is not a prime number.