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.
I have a table containing Month and Value and would like to add one column with cumulative total.
Below is the example I had:
The logic is:
MONTH 1 = 0
MONTH 2 = Value MONTH 1
MONTH 3 = Value MONTH 1 + Value MONTH 2
MONTH 4 = Value MONTH 1 + Value MONTH 2 + Value MONTH 3
...
MONTH 9 = Value MONTH 1 + Value MONTH 2 + Value MONTH 3 + Value MONTH 4 + Value MONTH 5 + Value MONTH 6 + Value MONTH 7 + Value MONTH 8.
Since I have value until MONTH 8, therefore new row should be added which is MONTH 9 (summation of value MONTH 1 until MONTH 8).
So far my solution is to add column and use this condition (which I find probably make POWER BI become slower) and I am unable to add one more row which is MONTH 9:
= Table.AddColumn(#"Previous Query", "CUMULATIVE", each if [MONTH] = 1 then 0 else if
[MONTH] = 2 then #"Previous Query"[VALUE]{0} else if
[MONTH] = 3 then #"Previous Query"[VALUE]{0}+#"Previous Query"[VALUE]{1} else if
[MONTH] = 4 then #"Previous Query"[VALUE]{0}+#"Previous Query"[VALUE]{1}+#"Previous Query"[VALUE]{2} else if
[MONTH] = 5 then #"Previous Query"[VALUE]{0}+#"Previous Query"[VALUE]{1}+#"Previous Query"[VALUE]{2}+#"Previous Query"[VALUE]{3} else if
[MONTH] = 6 then #"Previous Query"[VALUE]{0}+#"Previous Query"[VALUE]{1}+#"Previous Query"[VALUE]{2}+#"Previous Query"[VALUE]{3}+#"Previous Query"[VALUE]{4} else if
[MONTH] = 7 then #"Previous Query"[VALUE]{0}+#"Previous Query"[VALUE]{1}+#"Previous Query"[VALUE]{2}+#"Previous Query"[VALUE]{3}+#"Previous Query"[VALUE]{4}+#"Previous Query"[VALUE]{5} else if
[MONTH] = 8 then #"Previous Query"[VALUE]{0}+#"Previous Query"[VALUE]{1}+#"Previous Query"[VALUE]{2}+#"Previous Query"[VALUE]{3}+#"Previous Query"[VALUE]{4}+#"Previous Query"[VALUE]{5}+#"Previous Query"[VALUE]{6} else if
[MONTH] = 9 then #"Previous Query"[VALUE]{0}+#"Previous Query"[VALUE]{1}+#"Previous Query"[VALUE]{2}+#"Previous Query"[VALUE]{3}+#"Previous Query"[VALUE]{4}+#"Previous Query"[VALUE]{5}+#"Previous Query"[VALUE]{6}+#"Previous Query"[VALUE]{7} else if
[MONTH] = 10 then #"Previous Query"[VALUE]{0}+#"Previous Query"[VALUE]{1}+#"Previous Query"[VALUE]{2}+#"Previous Query"[VALUE]{3}+#"Previous Query"[VALUE]{4}+#"Previous Query"[VALUE]{5}+#"Previous Query"[VALUE]{6}+#"Previous Query"[VALUE]{6}+#"Previous Query"[VALUE]{7}+#"Previous Query"[VALUE]{8} else if
[MONTH] = 11 then #"Previous Query"[VALUE]{0}+#"Previous Query"[VALUE]{1}+#"Previous Query"[VALUE]{2}+#"Previous Query"[VALUE]{3}+#"Previous Query"[VALUE]{4}+#"Previous Query"[VALUE]{5}+#"Previous Query"[VALUE]{6}+#"Previous Query"[VALUE]{6}+#"Previous Query"[VALUE]{7}+#"Previous Query"[VALUE]{8}+#"Previous Query"[VALUE]{9} else
#"Previous Query"[VALUE]{0}+#"Previous Query"[VALUE]{1}+#"Previous Query"[VALUE]{2}+#"Previous Query"[VALUE]{3}+#"Previous Query"[VALUE]{4}+#"Previous Query"[VALUE]{5}+#"Previous Query"[VALUE]{6}+#"Previous Query"[VALUE]{7}+#"Previous Query"[VALUE]{8}+#"Previous Query"[VALUE]{9}+#"Previous Query"[VALUE]{9})
I would appreciate if someone can provide me much more simpler calculation
Solved! Go to Solution.
I'm posting some code for the cumulative column here:
Table.AddColumn(#"Previous Query", "Custom", each List.Sum(List.Range(#"Previous Query"[VALUE], 0, [MONTH]-1)))
May I request that you post data (not a picture) next time, for quicker answers?
---
If you want to add a row, you can create a one row table and append it (before adding the custom column above). I haven't tried it but it should work
Hi @Anonymous ,
Please use the following M to add a custom column:
=List.Sum(List.FirstN(#"Changed Type"[VALUE],[MONTH]-1))
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I'm posting some code for the cumulative column here:
Table.AddColumn(#"Previous Query", "Custom", each List.Sum(List.Range(#"Previous Query"[VALUE], 0, [MONTH]-1)))
May I request that you post data (not a picture) next time, for quicker answers?
---
If you want to add a row, you can create a one row table and append it (before adding the custom column above). I haven't tried it but it should work
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 |
---|---|
8 | |
6 | |
6 | |
6 | |
5 |
User | Count |
---|---|
9 | |
9 | |
8 | |
6 | |
6 |