The first four measures, K Value, k Value 2, N Value, and n Value 2 simply capture the current value selections from our tables, R10_K, R10__k, R10_N, and R10__n respectively. This is done by using the SELECTCOLUMNS function. As part of the SELECTCOLUMNS function, we provide default values for each of these measures.
To compute our Probability using the geometric distribution formula, we start by creating the __Error variable. The purpose of __Error is to determine whether the user has selected impossible values in the slicers. The entire __Error variable calculation is a series of logical OR statements that test various conditions. The first four conditions tested are whether or not the values of the four inputs to the geometric distribution formula are blank (ISBLANK). The second four conditions tested are for impossible conditions, such as the population size (N) being less than the desired number of successes (K).
We now calculate the numerator of our geometric distribution formula, __Numerator. This is accomplished by using the COMBIN function. The COMBIN function does all of the hard work of computing the binomial distributions (combinations). We wrap the calculation in an ISERROR statement to catch any other possible errors not accounted for by our __Error variable. If there is an error, our __Numerator is set to an impossible value, -1. Otherwise, we repeat our calculation. The calculation of our __Denominator variable is done in the same manner as our __Numerator variable.
Finally, in our RETURN statement we check if there has been an error by using a logical OR construct to see if __Error is FALSE or if __Numerator or __Denominator is -1. If there has been an error, we return Bad Parameters. Otherwise, we simply divide our __Numerator by our __Denominator.