Forum Discussion

will1329's avatar
will1329
Frequent Visitor
8 years ago
Solved

SQRT error on PowerBI/PowerPivot when using column references

Hi,   I am attempting to do a workaround for the lack of NORMSINV function in PowerBI/PowerPivot. Part of my formula is: B = 1.96*SQRT(1.96^2+4*[NUMERATOR]*(1-[NUMERATOR]/[DENOMINATOR]))   When ...
  • Greg_Deckler's avatar
    8 years ago

    The documentation on SQRT states that it returns an error for negative numbers. You are most likely getting negative numbers passed to the SQRT function. To test, try creating this column:

     

    D = VAR myvalue = [NUMERATOR]/[DENOMINATOR]
        VAR myvalue2 = 1.96^2
        VAR myvalue3 = myvalue2+4*[NUMERATOR]*(1-myvalue)
        RETURN myvalue3
    //    RETURN 1.96*SQRT(myvalue3)

    If you see negative numbers, you have your answer. See documentation here:

     

    https://msdn.microsoft.com/en-us/library/ee634559.aspx

     

    Note the Remarks section.

     

    You could potentially fix this by wrapping the inside of the SQRT with an ABS. You could create a VAR to see if the value that you are taking the SQRT of is negative and, if so, multiply by -1 outside of the SQRT if you really need the negatives.

  • Dave1's avatar
    8 years ago

    Hi, 

     

    The issue is caused by negative results for SQRT function.

    Create a measure for your numerator = sum(YourNumerator)

    Create a measure for your denominator =  sum(YourDenominator)

     

    Test logic

        Measure = Measure = 1.96*SQRT(1.96^2+4*1*(1-1/1))    === 3.84

    Prod Code

        Measure2 = Calculate(1.96*SQRT(ABS(1.96^2+4*[sum1]*(1-[sum1]/[Sum2]))))

     

    Measure and Measure 2 produce the same result for Field A, where Numerator and denominator are 1.