Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreThe FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now
hi all.
i have a question about some product table
there are
[Prodcode], [porductNM] , [Date], [salesamount], [salesprice]
that i want is addcolumns which one value is cumulative value with [salesamount] and [salesprice]
with date
if change next year -> reset cumulative
for example
Solved! Go to Solution.
hi, @theopa
sort = Table.Sort(your_table, {"porductNM", "Date"}),
f = (t as table) as table =>
[rec = List.Buffer(Table.ToRecords(t)),
gen = List.Generate(
() => [i = 0, r = rec{0}, rt = [Csalesamount = r[salesamount], Csalesprice = r[salesprice]]],
(x) => rec{x[i]}? <> null,
(x) =>
[i = x[i] + 1, r = rec{i},
rt =
[Csalesamount = x[rt][Csalesamount] + r[salesamount],
Csalesprice = x[rt][Csalesprice] + r[salesprice]]
],
(x) => x[r] & x[rt]
),
z = Table.FromRecords(gen)][z],
g = Table.Group(
sort, {"porductNM", "Date"},
{{"rows", each f(Table.Sort(_, "Date"))}},
GroupKind.Local,
(s, c) => Byte.From(Date.Year(s[Date]) <> Date.Year(c[Date]) or (s[porductNM] <> c[porductNM]))),
expand = Table.ExpandTableColumn(g, "rows", {"salesamount", "salesprice", "Csalesamount", "Csalesprice"})
hi, @theopa
sort = Table.Sort(your_table, {"porductNM", "Date"}),
f = (t as table) as table =>
[rec = List.Buffer(Table.ToRecords(t)),
gen = List.Generate(
() => [i = 0, r = rec{0}, rt = [Csalesamount = r[salesamount], Csalesprice = r[salesprice]]],
(x) => rec{x[i]}? <> null,
(x) =>
[i = x[i] + 1, r = rec{i},
rt =
[Csalesamount = x[rt][Csalesamount] + r[salesamount],
Csalesprice = x[rt][Csalesprice] + r[salesprice]]
],
(x) => x[r] & x[rt]
),
z = Table.FromRecords(gen)][z],
g = Table.Group(
sort, {"porductNM", "Date"},
{{"rows", each f(Table.Sort(_, "Date"))}},
GroupKind.Local,
(s, c) => Byte.From(Date.Year(s[Date]) <> Date.Year(c[Date]) or (s[porductNM] <> c[porductNM]))),
expand = Table.ExpandTableColumn(g, "rows", {"salesamount", "salesprice", "Csalesamount", "Csalesprice"})
thank you a lot
it's very good solution
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 6 | |
| 6 | |
| 5 |