Adding a SUM row to a query in google sheet - arrays

I have a Google Sheet and I want to use a Query to dynamically use some data and calculate the sum from some particular columns. I can collect the data well. Then when I want to add the SUM of the columns I have an error. Below is the code is used:
={QUERY(data;"SELECT A, B, C, D, E, F, G ORDER BY E DESC";1);{
"TOTAL";
SUM('Données'!$E$1:$E)
}}
Can you help me? I would like to have the sum of columns D,E,F at the last line.
THank you

try:
={QUERY(data; "select A,B,C,D,E,F,G where A is not null order by E desc"; 1);
"Total"\""\SUM(Données!C2:C)\SUM(Données!D2:D)\SUM(Données!E2:E)\""\""}

The array sizes are different so you cannot group without "appending" the missing columns.
={QUERY(data,"SELECT A, B, C, D, E, F, G ORDER BY E DESC",1);{
"TOTAL",,
SUM('Données'!$C$1:$C),
SUM('Données'!$D$1:$D),
SUM('Données'!$E$1:$E),,
}}

Related

How to pass variable arguments to the Cube function in spark sql?

How to pass variable arguments to the Cube function in spark sql and also agg function of the cube?
I have a list of columns, and I want to find the cube function on the columns and also aggerations function.
For example:
val columnsInsideCube = List("data", "product","country")
val aggColumns = List("revenue")
I want something like this:
dataFrame.cube(columns:String*).agg(aggcolumns:String*)
This is not like passing scala array to the Cube.
Cube is predefined class in the datafram.we have to send it in a proper manner.
You could use
Spark (new in version 1.4)
import pyspark.sql.DataFrame.cube
df.cube("name", df.age).count().orderBy("name", "age").show()
see also How to use "cube" only for specific fields on Spark dataframe?
or HiveSQL
GROUP BY a, b, c WITH CUBE
or which is equivalent to
GROUP BY a, b, c GROUPING SETS ( (a, b, c), (a, b), (b, c), (a, c), (a), (b), (c), ( ))
https://cwiki.apache.org/confluence/display/Hive/Enhanced+Aggregation,+Cube,+Grouping+and+Rollup#space-menu-link-content
or you could use other libraries like
import com.activeviam.sparkube._

Excel: Removing Duplicate Values Using Array Formula For Multiple Columns

I am trying to remove the duplicates from 7 different columns and combine the unique values into one column and I can't find a way to do that using an Excel formula
I've tried the array approach below, but it doesn't work for for more than one column:
=INDEX($A$11:$A$100000, MATCH(0, COUNTIF($C$11:C11,$A$11:$A$100000), 0))
Here's what I'd like ideally:
Starting data:
Column 1: a b d c b i
Column 2: c g h f d c
Column 3: f e a g b a
Ending result:
a
b
c
d
e
f
g
h
i
...
(order not important)
Any solutions would be appreciated.
Not sure if this answers the question exactly, but you could try using COUNTIFS to identify rows where combinations of two or more columns contain duplicate values:
=COUNTIFS($B:$B,$B1,$C:$C,$C1)
This formula will return the number of rows where the value in B1 and C1 is duplicated. You can copy and paste it down to every row in your formula, or use it as an array formula.
There's more on how to do this here:
http://fiveminutelessons.com/learn-microsoft-excel/find-duplicate-rows-excel-across-multiple-columns

Excel lookup in multiple column array, return row

I need to lookup the value of something in a table and then return the row that it's in. The value can be in any column, so Match doesn't seem ideal. What's the best way to do this?
As an example, say the table has 2 columns. Column 1 has A, B, C, D. Column 2 has E, F, G, H. I want to find out which row "G" is in, so I want to somehow return "3" without knowing beforehand that "G" is in column 2.
Please try:
=IFERROR(MATCH("g",A:A,0),MATCH("g",B:B,0))
and so on if more columns.
Assuming your data isn't duplicated, given this layout:
Column 1 Column 2
A E
B F
C G
D H
,this formula:
=MAX(IF(A1:B5="G",ROW(A1:B5),0))
will do what you want. In this case it would return 4. It also has the ability to work with an infinte number of columns (if nothing is duplicated, also a lot of columns might impact performance)
It's an array formula so you have to confirm it with Ctrl + Shift + Enter

Merge multiple 3D arrays matlab

I have a 3 sets of CT data each in it's own 700x700x512 array and I want to merge them into just one single array.
I had a look at the cat() function but didn't really understand how you set the dim variable- i.e. say for two simple 3x3x3 arrays, A & B, can I use AB_merge = cat(dim, A, B);
Thanks for any help!
The dim variable sets along which dimension you want to concatenate the images.
So if you want them 'on top of each other' that is along the 3rd dimensions:
AB_merge=cat(3, A, B);
If it is side by side along the x-axis:
AB_merge=cat(1, A, B);
etc.

Excel: Pair things up between two columns (A and B), and show unpaired values in columns C and D

Excel buffs:
There are many results showing up when searching for comparisons between two columns (ie: using VLOOKUP) but none of the results I have looked so far seems to do what I need in this particular way:
Column A has following values: Z, Q, V, V, T, T
Column B has following values: V, T, T, M
Column C will display Z, Q, V (here we have one V because one set of 'V' pairs up, leaving us with one unpaired 'V')
Column D will display M
The other examples I've seen so far assumes Column C will not have 'V' in it because it's already found in Column A, regardless of how many times it showed up.
Basically, instead, I need values between two columns paired up and removed, but leave me with any "odd ones" out.
I've been unable to figure this one out using formulae - I've resorted to sorting everything first, then shifting cells in either Column A or B downwards until Columna A and B either have matching values or odd one out in each row
Thanks in advance
Edit: Another way of saying it: I'd like to "eliminate" paired up values from Columns A and B, until all pairs have been removed, leaving me with remaining values in Column A and B
Let's make the assumption that the answers in C/D are allowed to reside in the same row as the unmatched originals in A/B.
Here's the formula for C1, copy and paste it down:
=REPT(A1,
MAX(0,MIN(1,COUNTIF($A:$A,A1)
-COUNTIF($B:$B,A1)
-IF(ROW()=1,0,COUNTIF(OFFSET($C$1,0,0,ROW()-1,1),A1))
)))
Basically, we want to "repeat" the corresponding value in column A if we haven't found a match for it in B and we haven't already accounted for it in C so far.
There's logic in there to ensure that OFFSET() doesn't refer to a zero-height range, and that we repeat either 0 or 1 time, no more and no less, on each row of C.
The formula for D1 is similar, but reversed to compare B back to A:
=REPT(B1,
MAX(0,MIN(1,COUNTIF($B:$B,B1)
-COUNTIF($A:$A,B1)
-IF(ROW()=1,0,COUNTIF(OFFSET($D$1,0,0,ROW()-1,1),B1))
)))

Resources