Sum a column of percents

I’m trying to sum a column of percents so that students can see their responses calculated to 100%…I’ve found some things but they didn’t exactly work how I needed. If it helps, I’m editing an activity I found for decimals/fractions to include percents…teaching 6th graders the equivalence of fractions-decimals-percents (and models)

I’m just starting out…please be patient and speak slowly (lol)…I’ve been using code from other responses to questions to try to figure things out on my own but haven’t found something that works for this.

Welcome, and happy to help! No need to apologize for being new to this stuff. Everyone starts off new! :smiley:

Please could you post a link to the in-progress activity you are working on. That will help people to find any bugs, suggest or write fixes, etc.


Here’s the activity that I copied and started editing…it is slide 9 that I’m now trying to figure out. There were other things that I think I have fixed in my own way (like the “of” showing up when I tried to include a %).

Thank you for any help and insight you can provide…I took a note from someone…don’t create you own code, borrow and edit what others have already done…this is where I got stuck.

Thanks for posting that. Here’s an edited version of your activity, with screen 9 now summing the percentages:

The relevant CL code is this:

proportion_sum =simpleFunction("a+b+c+d","a","b","c","d").evaluateAt(table2.cellNumericValue(1,5),table2.cellNumericValue(2,5),table2.cellNumericValue(3,5),table2.cellNumericValue(4,5))

percent_sum = simpleFunction("100*a","a").evaluateAt(proportion_sum)

cellContent(5,5): when isDefined(percent_sum) `Total:\ ${percent_sum}%` otherwise ` `

It’s not very elegant, but it seems to work!


Oh wow…it would’ve taken me a while to get there. Thank you for the help!!!
I’m determine to learn how to create and edit…want to be able to provide my teachers with as many good activities as I can

1 Like

Raj’s answer is good, but I’ll add that doing calculations in the calculator is often easier, so it’s a good technique to practice.

You can take the whole column from the table and drop it into the graph as a numberList in the graph’s CL. I made a list in the graph called percents, and this is putting those values from column 5 into the list.

numberList(`p_{ercents}`): table2.columnNumericValues(5)

Then, inside the graph, I added two lines at the top. One to hold the list with the empty brackets, and then the calculation to multiply the list values by 100 and add them up. That gets stored into a new variable which is then referred to in the note component to display the total.

If you are working on a screen without a graph, you can always add one in and set hidden to true. When there are lots of calculations or anything complex, I usually try to do that because the CL can get unwieldy.


Thanks, Dan!
When I was writing that ugly simpleFunction(“a+b+c+d”,“a”,“b”,“c”,“d”) part, I was thinking to myself “There has got to be a better way!”.
Shifting the data into the graphing calculator and doing the arithmetic there is much better!

I do find it a little surprising that the CL scripts don’t directly support basic arithmetic, e.g. proportion_sum = a+b+c+d. However, I don’t know anything about how CL was developed, or the design trade-offs that were run up against.


Yeah, I don’t know either. But not being able to directly perform operations was definitely one of the harder things for me to wrap my head around when I first starting doing CL work. That along with the order of the code not mattering outside of when statements.

1 Like

That is a great solution for what I was trying to do!! Thank you for taking the time!! I definitely have a lot to learn but I’m thankful there are people willing to help.

I have spent the better part of today trying to pull the code you suggested into a copy of my original version trying to replicate what you did to add up the percents in the table on slide 9…I added a note under the table and added the code to it but I have an error that I can’t seem to get gone. I’ve looked side by side on each of the components of that slide but do not see where my error is.
I’m trying to “learn” on my own so that I can replicate these ideas when I’m ready to create my own activities. Not sure what I’m missing though. Do you see anything that is causing the “!” on the new component? Thank you!

Sure, I’ll look. Make sure to publish the activity. Which slide do you want checked?

Thank you! Whelp…I think I deleted the version I was working on…trying to clean up the open tabs. :neutral_face:
It’s Monday…
I’ll get back with you if I find it.

Yep…I deleted it. I know it asked me if I was sure I wanted to delete…guess my processing skills are a little behind today.
Thank you for your help on the issue though…

That’s a bummer - I hate when I do that. I can make another example if it’s helpful - just tell me what slide you’re working on and what you want it to do.

If you haven’t restarted your computer, Ctrl+Shift+T or Cmd+Shift+T will bring back closed tabs. When editing activities, I’ve found it puts me where I left off.

I’m trying that…it does open the original copy but the changes that I made are not there…I’m trying to redo them (all part of the learning process, right?) :upside_down_face:

Ok…so I think I’ve updated it using the code that you added to your shared file…but on slide 9 there is an “!”…this is the component that was added to help find the sum of the percents. I added the component as a “note”…was that the correct step?
Something isn’t correct…

You needed to put CL in the graph that sinks the column into the graph. And then in the graph itself, I added two lines at the top to hold the data and do the calculation.

I’ll take a look at it…thank you!