Forum Discussion
DAX function not calculating decimal values correctly.
- Anonymous1 year ago
abansalgeoforce, Looks like Power BI is auto-converting the result to a fixed decimal with low precision at some point in the DAX chain.
abansalgeoforce You can force the calculation to be treated as a decimal by explicitly converting the values to decimals.
DAX
score_custom =
VAR var1 = table[column1] * 1.0
RETURN
SWITCH(
TRUE(),
ISBLANK(var1), 100,
var1 >= 0 && var1 <= 1, 100 + ((var1) / 1.0 * (-10)),
var1 > 1 && var1 <= 5, 90 + ((var1 - 1) / 4.0 * (80 - 90)),
var1 > 5 && var1 <= 10, 80 + ((var1 - 5) / 5.0 * (-10)),
var1 > 10 && var1 <= 15, 70 + ((var1 - 10) / 5.0 * (60 - 70)),
60
)
Instead of direct division, you can use the DIVIDE function to handle division operations and ensure decimal precision.
DAX
score_custom =
VAR var1 = table[column1]
RETURN
SWITCH(
TRUE(),
ISBLANK(var1), 100,
var1 >= 0 && var1 <= 1, 100 + DIVIDE(var1, 1.0) * (-10),
var1 > 1 && var1 <= 5, 90 + DIVIDE(var1 - 1, 4.0) * (80 - 90),
var1 > 5 && var1 <= 10, 80 + DIVIDE(var1 - 5, 5.0) * (-10),
var1 > 10 && var1 <= 15, 70 + DIVIDE(var1 - 10, 5.0) * (60 - 70),
60
)
- Anonymous9 months agoNot applicable
Did not solve the issue with the same problem Im having similar to the original question.
- Ashish_Mathur9 months agoSuper User
Hi,
Share some data to work with and show the expected result. Share data in a format that can be pasted in an MS Excel file.
- Rufyda9 months agoSuper User
Could you please share the ptoject file
Regards,
Rufyda Rahma | Microsoft MIE
https : https://www.linkedin.com/in/rufyda-abdelhadirahma/
Blog : https://medium.com/@rufydarahma