如何使用电源查询在同一列中进行增量求和?

发布于 2025-02-08 18:49:32 字数 271 浏览 2 评论 0原文

我有一个专栏[销售增长],该列是五行(例如5个月)。当前行=前一行或上一行的1.05%。每行都会继续下降。

在Excel中非常简单,假设我在B2中我要做的就是B1*1.05。但是,在电源查询中,事实证明很难解决。我已经看到了各种具有双索引和索引-1等的解决方案,这非常适合运行总计,但在我的情况下却不适合运行。

I have a column [Sales Growth] which as five rows (say for 5 months). Where current row = 1.05% of preceding row or previous row. And it continues down with each new row.

In Excel its very easy Suppose I am in B2 all I have to do is B1*1.05. But, in Power Query, it turned out to be very difficult to solve. I have seen all kinds of solutions with double indexing and Index -1 etc which is good for running total but not in my case.

Example from Excel for problem description. Same needs to be achieved in Power Query

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不…忘初心 2025-02-15 18:49:32

很难准确地告诉您您要做什么。但是,如果您从某个基本数字开始,并且始终将每一行增加相同的%,那么它只是数学复合公式。

Result = Base * (1+Rate)^PeriodNumber

或用PowerQuery术语,

= Base * Number.Power(1+Rate,[Column_Containing_Period])

示例代码:

let
Starting=100,
Growth=.05,
Source =  Table.FromList({0..50}, Splitter.SplitByNothing(), {"Index"}, null, ExtraValues.Error ),
#"Added Custom" = Table.AddColumn(Source, "Custom", each Starting*Number.Power(1+Growth,[Index]))
in #"Added Custom"

let
Starting=100,
Growth=.05,
Source =  List.Transform({0..50}, each Starting*Number.Power(1+Growth,_)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Result"}, null, ExtraValues.Error)
in #"Converted to Table"

”在此处输入图像描述”

It is hard to tell exactly what you are looking to do. But if you start with some base number and always increase each row by the same % then its just a math compounding formula.

Result = Base * (1+Rate)^PeriodNumber

or in powerquery terms,

= Base * Number.Power(1+Rate,[Column_Containing_Period])

sample code:

let
Starting=100,
Growth=.05,
Source =  Table.FromList({0..50}, Splitter.SplitByNothing(), {"Index"}, null, ExtraValues.Error ),
#"Added Custom" = Table.AddColumn(Source, "Custom", each Starting*Number.Power(1+Growth,[Index]))
in #"Added Custom"

or

let
Starting=100,
Growth=.05,
Source =  List.Transform({0..50}, each Starting*Number.Power(1+Growth,_)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Result"}, null, ExtraValues.Error)
in #"Converted to Table"

enter image description here

柳若烟 2025-02-15 18:49:32

查询1

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1QGSegameBmxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Factor = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Factor", type number}}),
    BF = List.Buffer(#"Changed Type"[Factor]),
    Result = Table.FromColumns(
        {   
            #"Changed Type"[Factor], fx(BF)
        },
        {
            "Factor",
            "Result"
        }

    )



in
    Result

相关功能

(values as list) as list =>

let 

result = List.Generate(

    () => [result = 100, counter = 0],
    each [counter] < List.Count(values),
    each [result = [result] * values{[counter] + 1}, counter = [counter]+1 ],
    each [result]

)

in result

enter image description here

Query 1

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1QGSegameBmxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Factor = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Factor", type number}}),
    BF = List.Buffer(#"Changed Type"[Factor]),
    Result = Table.FromColumns(
        {   
            #"Changed Type"[Factor], fx(BF)
        },
        {
            "Factor",
            "Result"
        }

    )



in
    Result

Relevant Function

(values as list) as list =>

let 

result = List.Generate(

    () => [result = 100, counter = 0],
    each [counter] < List.Count(values),
    each [result = [result] * values{[counter] + 1}, counter = [counter]+1 ],
    each [result]

)

in result
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文