Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formula Looping #78

Open
Jborhi opened this issue Feb 9, 2024 · 1 comment
Open

Formula Looping #78

Jborhi opened this issue Feb 9, 2024 · 1 comment

Comments

@Jborhi
Copy link

Jborhi commented Feb 9, 2024

First off, I love this plugin. However, I've noticed with larger tables there tends to be many repeated formulas to accomplish basic tasks.
Take the following table as an example.

| test 1         | test 2 | test 3 | test 4 |
| ----------- | ------ | ------ | ------ |
| Banana      | 1        | 2        | 3        |
| Orange      | 2        |           | 2        |
| Cherry       | 2        |           | 2        |
| total          | 5        | 2        | 7        |
<!-- TBLFM: @2$4=sum(@2$2..@2$3) -->
<!-- TBLFM: @3$4=sum(@3$2..@3$3) -->
<!-- TBLFM: @4$4=sum(@4$2..@4$3) -->
<!-- TBLFM: @>$2=sum(@I..@-1) -->
<!-- TBLFM: @>$3=sum(@I..@-1) -->
<!-- TBLFM: @>$4=sum(@I..@-1) -->

It takes 2 formulas, repeated 3 times each to accomplish both horizontal and vertical total calculation and only gets worse as the table grows in size, forcing repeated formulas to be added and leading to potential error.
Ideally, there would be some function that could iterate so many times similar to a for loop.

@sbliven
Copy link

sbliven commented May 29, 2024

The row sums can be merged by setting last column at once. This works because omitting the row from the destination applies the formula to all rows after the header.

| test 1 | test 2 | test 3 | test 4 |
| ------ | ------ | ------ | ------ |
| Banana | 1      | 2      | 3      |
| Orange | 2      |        | 2      |
| Cherry | 2.     |        | 2      |
| total  | 5      | 2      | 7      |
<!-- TBLFM: @>$2=sum(@2..@-1) -->
<!-- TBLFM: @>$3=sum(@2..@-1) -->
<!-- TBLFM: $>=sum($2..$3) -->

I don't think this is possible here for the column sums because the first column is non-integer. Trying to use <!-- TBLFM: @>=sum(@2..@-1) --> parses (silently) but shows an error in the console:

[DecimalError] Invalid argument: banana

What I would like is a way to include ranges in the destination specification. Eg <!-- TBLFM: @>$2..$3=sum(@2..@-1) -->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants