Forum Discussion
SQRT error on PowerBI/PowerPivot when using column references
- 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.
- 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.
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.
- will13298 years agoFrequent Visitor
Hi,
Thanks for the help both. Thought I'd made sure there were no negatives but a few had slipped past as the records contained blanks (12 out of 15million isn't too bad I think!). I've added your useful suggestions to deal with negatives for extra certainty. Just goes to show you should check your data before you analyse it
Thanks