Greg_Deckler's avatar
Greg_Deckler
Icon for Community Champion rankCommunity Champion
6 years ago

BINOM.DIST

In my recent quest to create or catalog as many DAX equivalents for Excel functions, this one plugs the gaps for the Binomial Distribution functions:

  • BINOMDIST
  • BINOM.DIST
  • BINOM.DIST.RANGE
  • BINOM.INV

For BINOMDIST and BINOM.DIST mass functions:

 

BINOM.DIST = DIVIDE(FACT([n]),FACT([n] - [x])*FACT([x])) * POWER([p],[x]) * POWER(1-[p],[n]-[x])

 

 

For BINOMDIST and BINOM.DIST cumulative and BINOM.DIST.RANGE:

 

BINOM.DIST.CUMULATIVE = 
    SUMX(
        ADDCOLUMNS(
            GENERATESERIES(0,[x]), // For range, change 0 and [x] to the range
            "B",DIVIDE(FACT([n]),FACT([n] - [Value])*FACT([Value])) * POWER([p],[Value]) * POWER(1-[p],[n]-[Value])
        ),
        [B]
    )

 

For BINOM.INV:

 

BINOM.INV = 
    VAR __Alpha = [Alpha]
    VAR __Table =
        ADDCOLUMNS(
            GENERATESERIES(0,[n]), // For range, change 0 and [x] to the range
            "B",DIVIDE(FACT([n]),FACT([n] - [Value])*FACT([Value])) * POWER([p],[Value]) * POWER(1-[p],[n]-[Value])
        )
    VAR __CumulativeTable = 
        ADDCOLUMNS(
            __Table,
            "Cumulative",SUMX(FILTER(__Table,[Value] <= EARLIER([Value])),[B])
        )
RETURN
    MINX(
        FILTER(
            __CumulativeTable,
            [Cumulative] >= __Alpha
        ),
        [Value]
    )

 

NOTE: I use the factorial form of the binomial distribution formula because in testing it was more performant than the form using combinations. On average, about 25% less time to return results per the Performance Analyzer. But, for reference, BINOM.DIST1 is the combination form:

BINOM.DIST1 = COMBIN([n],[x]) * POWER([p],[x]) * POWER(1 - [p],[n] - [x])

No RepliesBe the first to reply