Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. 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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
12 | |
8 | |
8 | |
7 |
User | Count |
---|---|
15 | |
13 | |
8 | |
7 | |
6 |