tgrosinger / md-advanced-tables

A text editor independent library to enable formatting and Excel-style navigation, and spreadsheet formulas to Markdown tables.
MIT License
151 stars 30 forks source link

Feature Request: @index #13

Open duquewu opened 3 years ago

duquewu commented 3 years ago

@index | $index means number of current row | column.

Before Calculate No. ArgA ArgB Operator Result
11 22 +
33 44 -
55 66 *
77 88 /
<!-- TBLFM: @2$<..@>=@index -->
<!-- TBLFM: @2$>=($2+$3) -->
<!-- TBLFM: @3$>=($2-$3) -->
<!-- TBLFM: @4$>=($2*$3) -->
<!-- TBLFM: @5$>=($2/$3) -->
After Calculate No. ArgA ArgB Operator Result
1 11 22 + 33
2 33 44 - -11
3 55 66 * 3630
4 77 88 / 0.875
tgrosinger commented 3 years ago

Hmm this sounds like a nice addition.

I would like to add it, but probably will not be able to get to it for a little bit. I'm very open to pull requests though if someone wants to beat me to it!

kilmc commented 1 year ago

This doesn't fully address the problem but for people who don't mind re-running the function if you add/remove/re-order rows, this works pretty nicely. Certainly sorted my needs so I figured I'd share ☺️

| #   | Sandwich      |
| --- | ------------- |
| 1   | Italian Combo |
| 2   | Reuben        |
| 3   | B.L.T.        |
<!-- TBLFM: @I$<..@>$<=(@-1+1) -->

Thanks @tgrosinger for a great plugin.

danetrata commented 1 year ago

@kilmc's solution can further be refined to @+0 which sort of makes sense.

Here's an example of it running in a budget table.

| Name     | Credit  | Debit  |      Sum |   Total |
| -------- | ------- | ------ | --------:| -------:|
| Income   | 3628.47 |        |  3628.47 | 3628.47 |
| AA       |         | 400    |  -400.00 | 3228.47 |
| Costco   |         | 272.59 |  -272.59 | 2955.88 |
| Amazon   |         | 35     |   -35.00 | 2920.88 |
| Freedom  |         | 140    |  -140.00 | 2780.88 |
| Upstart  |         | 532.75 |  -532.75 | 2248.13 |
| B&H      |         | 30     |   -30.00 | 2218.13 |
| Guitar   |         | 20     |   -20.00 | 2198.13 |
| Discover |         | 91     |   -91.00 | 2107.13 |
| Venmo    |         |        |     0.00 | 2107.13 |
| Paypal   |         |        |     0.00 | 2107.13 |
| Sara     |         | 1000   | -1000.00 | 1107.13 |
|          |         |        |     0.00 | 1107.13 |
<!-- TBLFM: $4=0::$5=0 -->
<!-- TBLFM: $4=($2 - $3);%.2f -->
<!-- TBLFM: @I$>..@>$>=sum(@I$4..@+0$4) -->