简体   繁体   English

标准化 Power 查询中的小数位

[英]Standardise decimal places in Power query

Pretty simple question but essentially I have a comparison where I want to return the modal value in a column.非常简单的问题,但基本上我有一个比较,我想在列中返回模态值。 In some cases, I'm getting 0.50, and 0.5.在某些情况下,我得到 0.50 和 0.5。 if both forms of 0.5 are equally present.如果 0.5 的两种形式同样存在。 I suspect this is because of the difference in the decimals (though it may not be).我怀疑这是因为小数点不同(尽管可能不是)。

Regardless it's not obvious how in excel to get all values to be rounded to the same number of decimal places.无论如何,如何在 excel 中将所有值四舍五入到相同的小数位数并不明显。

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type number}}),
    #"Inserted Rounding" = Table.AddColumn(#"Changed Type", "Round", each Number.Round([Column1], 2), type number)
in
    #"Inserted Rounding"

Rounding only works when a decimal is present.舍入仅在存在小数时有效。

Essentially what I wish to achieve:基本上我希望达到的目标:

在此处输入图像描述

Power Query does not have an option to set a numberformat for a column. Power Query 没有为列设置数字格式的选项。

Setting the data type to Currency.Type may result in a two decimal display (with four decimal precision), but there are instances where more decimals might be displayed.将数据类型设置为Currency.Type可能会导致显示两位小数(精度为四位小数),但在某些情况下可能会显示更多小数。 Combining Rounding and Currency.Type would probably always result in a two decimal display (at least it seems to here).结合 Rounding 和 Currency.Type 可能总是会导致显示两位小数(至少在这里看起来)。

If you want to be certain all values are displayed with two decimals, you will need to use a text formatted column, but the values would no longer be numeric.如果您想确定所有值都以两位小数显示,则需要使用文本格式的列,但这些值将不再是数字。 You would also have to use this method if you want a different fixed number of decimals.如果您想要不同的固定小数位数,您还必须使用此方法。

= Table.TransformColumns(Source, {"Column1", each Number.ToText(_,"0.00")})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM