Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Ok, i have about 2000 itens, and i need to know the sum of each one of these because i will use it as a condition for my dashboard.
I know this probably is something dumb, but i just started at power bi, so i guess is fair use of the forum haha'
Edit: is there anyway to create a column that shows me a acumulative result, i mean:
Something like this..
I would like to learn both ways if possible.
Solved! Go to Solution.
Hi @Anonymous
I assume you want a grouped running total where the total resets when there's a change in name/Material, or from x to y in your 2nd image.
Here's a sample PBIX file with all the code shown below.
The code for a grouped running total in Power Query/M is
let
GRT = (values as list, grouping as list) as list =>
let
GRTList = List.Generate
(
()=> [ GRT = values{0}, i = 0 ],
each [i] < List.Count(values),
each try
if grouping{[i]} = grouping{[i] + 1}
then [GRT = [GRT] + values{[i] + 1}, i = [i] + 1]
else [GRT = values{[i] + 1}, i = [i] + 1]
otherwise [i = [i] + 1]
,
each [GRT]
)
in
GRTList,
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc1bCsAwCETRvfgdQU3tYy0h+0i7+iYtJSP9OxdGLIUaJeJdhGp6A80KPqY1bBwqBK/yvzm7M5hD6IblEAbuXx5f3QuYLc/4Hg6b+RzpGNUb", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Material = _t, Teste = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Teste", Int64.Type}}),
BufferedValues = List.Buffer(#"Changed Type"[Teste]),
BufferedGrouping = List.Buffer(#"Changed Type"[Material]),
GroupedRunningTotal = Table.FromList(GRT(BufferedValues, BufferedGrouping), Splitter.SplitByNothing(), {"GRT"}, null, ExtraValues.Error),
Columns = List.Combine({Table.ToColumns(#"Changed Type"),Table.ToColumns(GroupedRunningTotal)}),
#"Converted to Table" = Table.FromColumns(Columns,List.Combine({Table.ColumnNames(#"Changed Type"),{"GRT"}}))
in
#"Converted to Table"
which gives you this
But if you want a running total where you're just adding the next value to thelast one, use this
let
RT = (values as list, grouping as list) as list =>
let
RTList = List.Generate
(
()=> [ RT = values{0}, i = 0 ],
each [i] < List.Count(values),
each [RT = [RT] + values{[i] + 1}, i = [i] + 1]
,
each [RT]
)
in
RTList,
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc1bCsAwCETRvfgdQU3tYy0h+0i7+iYtJSP9OxdGLIUaJeJdhGp6A80KPqY1bBwqBK/yvzm7M5hD6IblEAbuXx5f3QuYLc/4Hg6b+RzpGNUb", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Material = _t, Teste = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Teste", Int64.Type}}),
BufferedValues = List.Buffer(#"Changed Type"[Teste]),
BufferedGrouping = List.Buffer(#"Changed Type"[Material]),
RunningTotal = Table.FromList(RT(BufferedValues, BufferedGrouping), Splitter.SplitByNothing(), {"RT"}, null, ExtraValues.Error),
Columns = List.Combine({Table.ToColumns(#"Changed Type"),Table.ToColumns(RunningTotal)}),
#"Converted to Table" = Table.FromColumns(Columns,List.Combine({Table.ColumnNames(#"Changed Type"),{"RT"}}))
in
#"Converted to Table"
which gives you this
Phil
If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.
Proud to be a Super User!
Hi @Anonymous
I assume you want a grouped running total where the total resets when there's a change in name/Material, or from x to y in your 2nd image.
Here's a sample PBIX file with all the code shown below.
The code for a grouped running total in Power Query/M is
let
GRT = (values as list, grouping as list) as list =>
let
GRTList = List.Generate
(
()=> [ GRT = values{0}, i = 0 ],
each [i] < List.Count(values),
each try
if grouping{[i]} = grouping{[i] + 1}
then [GRT = [GRT] + values{[i] + 1}, i = [i] + 1]
else [GRT = values{[i] + 1}, i = [i] + 1]
otherwise [i = [i] + 1]
,
each [GRT]
)
in
GRTList,
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc1bCsAwCETRvfgdQU3tYy0h+0i7+iYtJSP9OxdGLIUaJeJdhGp6A80KPqY1bBwqBK/yvzm7M5hD6IblEAbuXx5f3QuYLc/4Hg6b+RzpGNUb", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Material = _t, Teste = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Teste", Int64.Type}}),
BufferedValues = List.Buffer(#"Changed Type"[Teste]),
BufferedGrouping = List.Buffer(#"Changed Type"[Material]),
GroupedRunningTotal = Table.FromList(GRT(BufferedValues, BufferedGrouping), Splitter.SplitByNothing(), {"GRT"}, null, ExtraValues.Error),
Columns = List.Combine({Table.ToColumns(#"Changed Type"),Table.ToColumns(GroupedRunningTotal)}),
#"Converted to Table" = Table.FromColumns(Columns,List.Combine({Table.ColumnNames(#"Changed Type"),{"GRT"}}))
in
#"Converted to Table"
which gives you this
But if you want a running total where you're just adding the next value to thelast one, use this
let
RT = (values as list, grouping as list) as list =>
let
RTList = List.Generate
(
()=> [ RT = values{0}, i = 0 ],
each [i] < List.Count(values),
each [RT = [RT] + values{[i] + 1}, i = [i] + 1]
,
each [RT]
)
in
RTList,
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc1bCsAwCETRvfgdQU3tYy0h+0i7+iYtJSP9OxdGLIUaJeJdhGp6A80KPqY1bBwqBK/yvzm7M5hD6IblEAbuXx5f3QuYLc/4Hg6b+RzpGNUb", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Material = _t, Teste = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Teste", Int64.Type}}),
BufferedValues = List.Buffer(#"Changed Type"[Teste]),
BufferedGrouping = List.Buffer(#"Changed Type"[Material]),
RunningTotal = Table.FromList(RT(BufferedValues, BufferedGrouping), Splitter.SplitByNothing(), {"RT"}, null, ExtraValues.Error),
Columns = List.Combine({Table.ToColumns(#"Changed Type"),Table.ToColumns(RunningTotal)}),
#"Converted to Table" = Table.FromColumns(Columns,List.Combine({Table.ColumnNames(#"Changed Type"),{"RT"}}))
in
#"Converted to Table"
which gives you this
Phil
If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.
Proud to be a Super User!
User | Count |
---|---|
106 | |
89 | |
81 | |
76 | |
73 |
User | Count |
---|---|
112 | |
104 | |
96 | |
74 | |
66 |