DAX 测试整数 [英] DAX to Test for Whole Number

查看:15
本文介绍了DAX 测试整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的 Actuals 列:

I have a Actuals column like so:

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 评估为真,但我总是得到假.

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") & "%"

结果:

内置样式通用编号"可以正确处理您的情况,您只需在格式化字符串中添加 % 符号.无需测试整数.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆