如何在 Power BI 中有条件地显示度量中的小数

问题描述 投票:0回答:3

假设我有一个像这样的简单措施:

SimpleMeasure = MyTable[Column1]/MyTable[Column2]

是否可以根据值显示小数位数?例如,如果我的度量计算出数字 500,那么我不想看到 500.00,而是看到 500。但是,如果我的度量计算出 0.56,那么我希望看到像这样显示到小数点后两位的值,而不是四舍五入到1号。

因此,可能的可视化表格如下所示:

Store   SimpleMeasure
00      10
01      18
02      0.67
03      6

提前谢谢您!

powerbi dax
3个回答
1
投票
IF(
[SimpleMeasure] < 1, FORMAT([SimpleMeasure], "#,##0.##",
FORMAT([SimpleMeasure], "#,##0")
)

0
投票

稍微编辑@Conner的答案更正括号:

IF([SimpleMeasure] < 1, FORMAT([SimpleMeasure], "#,##0.##"),
FORMAT([SimpleMeasure], "#,##0")
)

-2
投票

您可以使用 Switch() 函数。它将返回第一个 True 结果。将值按 DESC 顺序排列 - 从最大值开始,然后到较小的值,然后到最低的值。例如:

Switch(
    True
    ,[SimpleMeasure]<1,Round([SimpleMeasure],2) -- 0.655->0.66
    ,[SimpleMeasure]>999,Round([SimpleMeasure],-2) --1044->1000
    ,[SimpleMeasure]>499,Round([SimpleMeasure],-1) -- 505,5->510
    ,[SimpleMeasure]>99,Round([SimpleMeasure],0)  -- 101,55->102        
    ,[SimpleMeasure]>1,Round([SimpleMeasure],1)  -- 99,43->99.4
)

或者/并且您可以在 Switch() 中使用 Format() 函数,使用 或 代替 Round(),例如:

Format([SimpleMeasure],"#,##0.#") 

Or
     
Format(Round([SimpleMeasure],1),"#,##0.#")

-- Both of them Format() will return  and show 99,43 as 99,4. 
-- Placeholer # returns a digit or nothing.
-- Placegholder 0 returns a digit or 0. 

Format() 和 Round() 的使用取决于您的任务。但对于选择性格式,您将需要 Switch()。

希望,答案能帮助您解决案件

© www.soinside.com 2019 - 2024. All rights reserved.