如何在Power BI [查询编辑器]中添加逗号千位分隔符

7
有一列数字,例如:
ex.
12876391

希望进行转换

12,876,391

在整个列中。 我在许多论坛中都找不到简单的解决方案。我该如何实现它?
4个回答

16

您可以先在 字段 面板中选择列,然后在 建模 -> 格式设置 下找到 千位分隔符 选项。

separator


它工作了,这正是我所需要的,非常感谢你。 - rane
1
我的数据源是AAS模型。因此,我没有通过建模进行格式化的选项。当我使用直接查询模式时,有没有解决这个问题的方法? - Trisa Biswas
如果数字是可视化本身完成的聚合计数,怎么办?例如将分类列放入多行卡中并选择计数(不同)。 - geominded

4
我有一张Google Analytics数据表,但没有"建模">"格式"选项。我再次去查看了普通的格式(油漆滚筒),除了“值” > “小数位数”这个选项是自动和灰色外,没有其他选项。
后来我发现,如果在“数据字段”区域单击要格式化的实际指标,您会发现,在顶部出现了两个新选项卡:表格工具和列工具。 列工具具有通常的Excel类型格式设置选项。

0

提醒一下 - @JSmart523 提供的解决方案很好,但有一个错误。最后一行应该是 List.Count(numberAsTextList) = 1,所以完整的代码如下:

    (n as number) as text =>
let
    numberAsTextList = Text.Split(Number.ToText(Number.Abs(n), null, "en-US"), "."),
    textWhole = numberAsTextList{0},
    fNextRecordInListGenerate = each
            let
                len = Text.Length([remaining])
            in
                if len = 0 then
                    [remaining = null]
                else
                    [remaining = Text.Start([remaining], List.Max({0, len - 3})), part = Text.End([remaining], 3)],
    nums = List.Reverse(List.Generate(
        () => fNextRecordInListGenerate([remaining = textWhole, part = ""]),
        each [remaining]  null,
        fNextRecordInListGenerate,
        each [part]
    )),
    ret = (if Number.Sign(n) = -1 then "-" else "")
        & Text.Combine(nums, ",")
        & (if List.Count(numberAsTextList) = 1 then "" else "." & numberAsTextList{1})
in
    ret

0
其他答案如果适用于您的情况会更好,但如果您真的需要在Power Query内部执行此操作,您可以使用以下代码:

fNumberToTextWithComma

(n as number) as text =>
let
    numberAsTextList = Text.Split(Number.ToText(Number.Abs(n), null, "en-US"), "."),
    textWhole = numberAsTextList{0},
    fNextRecordInListGenerate = each
            let
                len = Text.Length([remaining])
            in
                if len = 0 then
                    [remaining = null]
                else
                    [remaining = Text.Start([remaining], List.Max({0, len - 3})), part = Text.End([remaining], 3)],
    nums = List.Reverse(List.Generate(
        () => fNextRecordInListGenerate([remaining = textWhole, part = ""]),
        each [remaining] <> null,
        fNextRecordInListGenerate,
        each [part]
    )),
    ret = (if Number.Sign(n) = -1 then "-" else "")
        & Text.Combine(nums, ",")
        & (if List.Count = 1 then "" else "." & numberAsTextList{1})
in
    ret

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接