Copying a range remotely - emacs

I've got a table named FOO with the column ("Porc" |- 3 7 15 50 15 7 3) and I'm copying the numbers to another table, shown below. I'm doing it the hard way, cell for cell, but I was wondering if there is a way to copy that range of the remote table (A2 to the bottom) in a single command.
| Pr (%) | ROE de A | ROE de B |
|--------+----------+----------|
| 3 | -11.43 | -34.29 |
| 7 | 0. | -11.43 |
| 15 | 3.43 | 0. |
| 50 | 12. | 17.14 |
| 15 | 20.57 | 34.29 |
| 7 | 24. | 41.14 |
| 3 | 30.86 | 54.86 |
|--------+----------+----------|
| Média | 11.86 | 16.41 |
| Desvio | 8.37 | 17.61 |
#+TBLFM: #2$1=remote(FOO, A2)::#3$1=remote(FOO, A3)::#4$1=remote(FOO, A4)::etc
Thanks

It seems your answer is in the org-mode manual:
$3 = remote(FOO, ###$2)
copy column 2 from table FOO into
column 3 of the current table For the
second example, table FOO must have at
least as many rows as the current
table. Inefficient for large number of
rows.

A Kind of Corollary: Copying all fields in a given row
So just as:
$3 = remote(FOO, ###$2)
copies all the fields from a given column (col2) into column three of the new table, then:
#3 = remote(FOO, #1$$#)
copies all the fields from a given row (row1) into row 3.
There's something about how this standard reference form #r$c interacts with the ## and $# notation that makes this seem a bit abstruse. e.g. this is all the org manual has to say about this remote reference syntax:
## and $# can be used to get the row or column number of the field where the formula result goes.
Umm…?
Posting this example here because I found it all a bit mystifying and hope this helps some else save a few minutes when dealing with rows and tables in the awesome org-mode

Related

Combine multiple rows into single row in Google Data Prep

I have a table which has multiple payload values in separate rows. I want to combine those rows into a single row to have all the data together. Table looks something like this.
+------------+--------------+------+----+----+----+----+
| Date | Time | User | D1 | D2 | D3 | D4 |
+------------+--------------+------+----+----+----+----+
| 2020-04-15 | 05:39:45 UTC | A | 2 | | | |
| 2020-04-15 | 05:39:45 UTC | A | | 5 | | |
| 2020-04-15 | 05:39:45 UTC | A | | | 8 | |
| 2020-04-15 | 05:39:45 UTC | A | | | | 7 |
+------------+--------------+------+----+----+----+----+
And I want to convert it to something like this.
+------------+--------------+------+----+----+----+----+
| Date | Time | User | D1 | D2 | D3 | D4 |
+------------+--------------+------+----+----+----+----+
| 2020-04-15 | 05:39:45 UTC | A | 2 | 5 | 8 | 7 |
+------------+--------------+------+----+----+----+----+
I tried "set" and "aggregate" but they didn't work as I wanted them to and I am not sure how to go forward.
Any help would be appreciated.
Thanks.
tl;dr:
use fill() function to fill all empty values within each d1-d4 columns in the wanted group (AKA - the columns date+time+user) then dedup\aggregate to your heart's content.
long version
So the quickest way to do this is by using a window-function called "fill()".
What this function does for each given field in a column, it tells it:
"Look down. look up. find the closest non-empty value, and copy it!"
you can ofcourse limit it's sight (look only 3 rows above, for example) but for this example, don't need the limitation. so your fill function will look like this:
FILL($col, -1, -1)
So the "$col" will reference all the chosen columns. the "-1" says "unlimited sight".
finally, the "~" says "from column D1 to column D4".
So, function will look like this:
.
Which in turn will make your columns look like this:
.
Now you can use the "dedup" transformation to remove any duplications, and only 1 copy of each "group" will remain.
Alternatively, if you still want to use "group by", you can do that aswell.
Hope this helps =]
p.s
There are more ways to do this - which entails using the "pivot" transformation, and array unnesting. But in the process you'll lose your columns' names, and will need to rename them.

Tableau - Show multiple discrete string (dropdown) dimensions side-by-side in a single table

I have a list of survey results that looks similar to the following:
| Email | Question 1 | Question 2 |
| ----------------- | ---------- | ---------- |
| test#example.com | Always | Sometimes |
| test2#example.com | Always | Always |
| test3#example.com | Sometimes | Never |
Question 1 and Question 2 (and a few others) have the same discrete set of values (from a dropdown list on the survey).
I want to show the data in the following format in Tableau (a table is fine, but a heatmap or highlight table would be best):
| | Always | Sometimes | Never |
| ---------- | ------ | --------- | ----- |
| Question 1 | 2 | 1 | 0 |
| Question 2 | 1 | 1 | 1 |
How can I achieve this? I've tried various combinations of rows and columns and I just can't seem to get close to this layout. Do I need to use a calculated value?
As far as I know - it is not natively possible with Tableau, because what you have is kind of a pivot table.
What you can do is unpivot the whole table as explained here https://stackoverflow.com/a/20543651/5130012, then you can load the data into Tableau and create the table you want.
I did some dummy data and tried it.
That's my "unpivoted" table:
Row,Column,Value
test,q1,always
test,q2,sometimes
test1,q1,sometimes
test1,q2,never
test10,q1,always
test10,q2,always
test11,q1,sometimes
test11,q2,never
And that's how it looks in Tableau:

Crosstabs Crystal Reports Null value vs zero

I'm creating a crosstab report showing the survey history for gopher tortoises (if you must know what that is) monitoring stations. Not all stations are monitored for a given survey and sometimes when we monitor we don't find any and thus record a 0 which is a valid result.
In the crosstab when the station isn't used I would like it to say "N/A" or some other equivalent, but when it's a zero I want it to stay as zero.
I've found so much on how to change a null to a zero, but nothing when you want to keep the zero and somehow note the null.
Below is what the crosstab should look like. You'll see that the 0 in Station4 on 1/1/2004 is "real" (meaning we didn't find any) but all of the N/A's are when we didn't use the station.
Survey Dates
| | 1/1/2000 | 1/1/2002 | 1/1/2004 | 1/1/2006 |
|----------|----------|----------|----------|----------|
| Station1 | 9 | 5 | N/A | N/A |
| Station2 | 5 | 7 | 2 | 6 |
| Station3 | N/A | N/A | 6 | 9 |
| Station4 | 10 | 9 | 0 | 11 |
This is what the Oracle table look like for the 1/1/2000 survey as an example
| SurveyID | StationID | Number |
|----------|-----------|--------|
| 1 | 1 | 9 |
| 1 | 2 | 5 |
| 1 | 4 | 6 |
So, basically how to I keep the zero's and put some text in the nulls in a CR crosstab?
Thanks!
Because CR doesn't differentiate between nulls and actual zeros in the crosstab, you can try replacing actual zero values with a placeholder so you can tell the difference. Note that this solution will only work if you are trying to display the values and not do any aggregate calculations.
First, create a formula that will replace the zeros with a placeholder value. In this case, I'm using -1 since that number should never appear in the database.
//{#Survey Num}
local numbervar totalSurvey;
totalSurvey:={Table.ActiveBurrows} + {Table.InactiveBurrows};
if totalSurvey=0 then -1 else totalSurvey
Use this formula to create your crosstab. Now you need to set a display string so that everything appears correctly. Right-click one of your crosstab cells → hit "Format Field" → select the "Common" tab → then create a "Display String" formula. That formula should be something like:
if currentfieldvalue=-1 then "0" else if currentfieldvalue=0 then "N/A" else totext(currentfieldvalue,0,'')
Now you're basically just printing the real values over top of the placeholders.

Finding the last seven days in a time series

I have a spreadsheet with column A which holds a timestamp and updates daily. Column B holds a value. Like the following:
+--------------------+---------+
| 11/24/2012 1:14:21 | $487.20 |
| 11/25/2012 1:14:03 | $487.20 |
| 11/26/2012 1:14:14 | $487.20 |
| 11/27/2012 1:14:05 | $487.20 |
| 11/28/2012 1:13:56 | $487.20 |
| 11/29/2012 1:13:57 | $487.20 |
| 11/30/2012 1:13:53 | $487.20 |
| 12/1/2012 1:13:54 | $492.60 |
+--------------------+---------+
What I am trying to do is get the average of the last 7, 14, 30 days.
I been playing with GoogleClock() function in order to filter the dates in column A but I can't seem to find the way to subtract TODAY - 7 days. I suspect FILTER will also help, but I am a little bit lost.
There are a few ways to go about this; one way is to return an array of values with a QUERY function (this assumes a header row in row 1, and you want the last 7 dates):
=QUERY(A2:B;"select B order by A desc limit 7";0)
and you can wrap this in whatever aggregation function you like:
=AVERAGE(QUERY(A2:B;"select B order by A desc limit 7";0))

Emacs: Org-mode spreadsheet: targeting via hline

I'm trying to log my hours in org mode:
** Bob Johnson, Bob's SEO
| subject | time | minutes | total hours |
|-----------------------------------------------+---------------------------+---------+-------------|
| optimization report | 2011/07/11 8-10:00 PM PST | 120 | 2 |
| phonecall to dicuss report and plan of action | 2011/07/13 5:41 PM | 43 | 0.71666667 |
|-----------------------------------------------+---------------------------+---------+-------------|
| | | 249 | 4.15 |
#+TBLFM: $4=#0$-1/60::#6$3=vsum(#I..#II)
The main problem is the expression above that sums up total hours:
#6$3=vsum(#I..#II)
Should be something like:
#||+1$3=vsum(#I..#II)
So that as the spread sheet grows the last item in the second to last column will always sum the total. It doesn't work when I set it this way (and +II, and other ways) however.
Any ideas?
Thanks!
The closest you could come to relative references would be to change your formula to:
#+TBLFM: $4=$-1/60::#>$3=vsum(#I..#II)
The #0 is implied by -1.
For the second formula the #> means the last row, so as long as you don't add additional rows below your total row the results will be in the right place. If you add additional below it you will simply have to adjust the number of > signs.
EDIT:
You can also name the cell in question so that it doesn't get changed regardless:
Org-Manual
|-----------------------------------------------+---------------------------+---------+-------------|
| | | 163 | 2.7166667 |
| ^ | | total | total |
#+TBLFM: $4=$-1/60::$total=vsum(#I..#II)
You need the total name for both total rows, otherwise your minutes won't add up.
Use the M-S-up,down,left,right family of commands to manipulate (insert/delete row/column) the table, and the formula will be adjusted automatically.