DAX测试整数 [英] DAX to Test for Whole Number
问题描述
我的实际值列如下:
ID | Airport
------------
A | 98.4
B | 98.0
C | 95.3
我正在尝试将以上数字格式化为前端报告的百分比。我已在switch语句中编写了此代码-为简便起见,我将逻辑形式写为IF布尔值。
I'm attempting to format the numbers above into percentages for a front-end report. I have this written in a switch statement - for ease I'll just write the logic as an IF boolean.
example_measure =
VAR Nums = SELECTEDVALUES(Table[Actuals])
VAR FormatNums = IF(DIVIDE(ROUND(nums,1), nums) = 1,
format(nums,"0%"),format(nums,"0.0%")
-
RETURN
FormatNums
无论我做什么始终都会返回浮点值为 1f
no matter what I do this always returns a number with a floating point value of 1f
因此在98.0的原始数据中,我期望该格式返回 98%
而不是 98.0%
so in my raw data of 98.0 I'm expecting the format to return "98%"
rather than "98.0%"
这些度量用于单个卡上,并经过过滤,因此它们只能显示一个值或空白,这意味着它们只能显示一个值
the measures are used on individual cards, and are filtered so they can only ever show one value or blank, meaning they will only ever display one value on their own.
我喜欢使用 if(nums = int(nums)
评估为 98.0
为true,但我总是会出错。
I've toyed with using if(nums = int(nums)
which should evaluate to true for 98.0
but it I always get false.
推荐答案
有一个简单的方法-只需使用内置的格式代码即可:
There is a simpler way - just use built-in formatting codes:
Formatted Actuals =
VAR x = SELECTEDVALUE(Data[Actuals])
RETURN
FORMAT(x, "General Number") & "%"
结果:
< a href = https://i.stack.imgur.com/tKFPg.png rel = nofollow noreferrer>
内置样式常规编号可以正确处理您的情况,您只需要在格式化的字符串中添加%符号。无需测试整数。
Built-in style "General Number" handles your situation correctly, you just need to add % symbol to the formatted string. No need to test for whole numbers.
这篇关于DAX测试整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!