How to summarize values when column values are identical? - tableau-desktop

I am pretty much using Tableau as a pivot table here. How can I summarize the order volume column so that, because all of the previous column values are the same, it will read as 3 instead of 1 and 2? Sum() hasn't worked for me.
Thank you!!!
Screenshot

Based on what you provided as sample, you may want to calculate the max value for that specific column, in order to have just one "aggregated value".
Using the superstore dataset you can replicate this, trying to calculate the max Order ID for a specific customer regardless the number of rows:
{ FIXED [Customer Name] : max ([Order ID])}
The result could look like this:

Related

Excel/Sheets Consecutive Count Based on Two Conditions (function?)

I have a Google Sheet, and I'm trying to see if it's possible to get a consecutive count outputted in a third column based on the values of two other columns.
My columns are:
Column A: Will have a handful of text values that are "grouped" together. Likely around 30 of the same value, until it changes to another value. In the image above, these are text1, and text2.
Column B: Will have one of 3 values assigned to each value in column A. In the image above, these are id1, id2, id3.
Column C: Will output a consecutive count based on the values of the first two columns. My hope is that if there are multiple ID1,ID2 in consecutive order, they'll repeat that first +1 value; while ID3 is always plus 1 to the count. This is what I am trying to show in column C in the layout image above.
I've hit a wall with trying to accomplish this with various COUNTIF iterations.
Thanks for any help, or any better ideas to accomplish something similar.
(I'm hoping for a formula, but open to being pointed into a direction for a script if that's the only way).
You can try following formula:
=IF(A2=A1;IF(OR(B2="id3";B2<>B1);C1+1;C1);1)
It is also possible to do this as an array formula. I used offset ranges for column B in the first Countifs to check for a change in value but this made it a little awkward to get equal-sized arrays:
=ArrayFormula(if(A2:A="","",
countifs({"";B2:B}<>{B2:B;""},true,{A2:A;""},A2:A,row(A:A),"<"&row(A2:A),{B2:B;""},"<>id3")+
countifs(A2:A,A2:A,row(A2:A),"<="&row(A2:A),B2:B,"=id3")
))

Google Sheets: Add value to total if a row condition matches for infinite column

I am attempting to make a Google Sheet that has a column for a rate and a value of that rate. Each night I am adding a new value to the bottom of this list so I want it to continue as an infinite list. What this sheet should do is look down the list of rates, if the rate matches a predefined rate, it should add the corresponding value to the total for that rate. I have four common rates that occur in no particular order and with some given value. I would like to total the values for each of those rates and give them in the totals section so each rate can be easily referenced.
Is there a way to do this using Google Sheets built-in commands? Pseudocode would be something like IF(A2:A = rate, add value in B to total). I know to make an infinite reading of a column by A2:A, but I don't know how to check each value as it goes through that column. I have attached a test spreadsheet with some sample values and the output that should be given by the formula. Thank you in advance for your help.
https://docs.google.com/spreadsheets/d/19k1DMipSsI9tWSjTXrVAPzPoaenWS6WYmlwe201_WQk/edit?usp=sharing
I managed to discover my own answer using the SUMIF statement. My code for the rate of .75 is ""=SUMIF(A2:A,"=.75",B2:B)"". I ran into some more trouble with the section for a different rate because I was having trouble saying not equal to .75 or 1 or 1.5 or 1.75. I solved this problem by completely bypassing it and adding the all the values and subtracting away the values already added. I would still like to know how to give the list of "ors" if someone could shed some light on this. But I now have a working solution regardless. I have updated the test sheet to show the solution.

Randomize cells in Google Sheets

Is there a formula to randomize a column of data which keeps each item represented only once (has the same items)?
So:
APPLES
PEARS
BERRIES
Might come out as
PEARS
BERRIES
APPLES
Randbetween formulas no good here, as you might get two 'PEAR's.
There is a new "randomize range" feature available in the context menu after selecting a range:
]
The following approach implements the idea of pnuts, but without creating a column filled with random numbers:
=query({A2:A20, arrayformula(randbetween(0, 1e20 + row(A2:A20)))}, "select Col1 order by Col2", 0)
Here A2:A20 is the range to be permuted. The arrayformula generates a random integer for each. The query sorts the array by those random integers, but does not put the random numbers in the spreadsheet.
The entropy of randbetween is 64 bits, so collisions are extremely unlikely. And even if two random numbers happen to be equal, that will not generate repetitions; sorting by whatever column never does that. It only means the corresponding pair of entries will appear in their original order.
Came across this while looking for a formula to generate a set of random unique integers and ended up devising my own, so I'm leaving it here for anyone else looking for the same:
=SORT(SEQUENCE(A$1),RANDARRAY(A$1),FALSE) where A$1 is the count of integers to generate (expressed here as a cell reference because I like to create sheets where I can input a number in a cell rather than changing the formula, but this can of course be just a number.)
This can be expanded by adding the three other fields to SEQUENCE as explained in the function's documentation, or by wrapping it in an ARRAYCONSTRAIN to limit the count of entries returned without changing the minimum or maximum values of the generated entries. Hope all this makes sense!
I adopted a similar approach to user6655984 before I found this post.
RANDARRAY seemed to be a neat call once solution.
I had similar demands. Formula based, randomized return order, ability to have only unique records or not as the whim took me.
Right clicking to randomize range meant user interaction I didn't want and the data is dynamic.
I built in the random numbers into a query data range on the fly.
I get the flexibility of query (can easily expand the range, add returned columns filter criteria etc), I don't have to show the random numbers at all and can wrap it in UNIQUE if desired, it re-randomizes with each recalc.
Have some data in column A2:A.
To see the inline data range.
={RANDARRAY(ROWS($A$2:$A)),$A$2:$A}
Query (inc duplicates), filter out empty.
=QUERY({RANDARRAY(ROWS($A$2:$A)),$A$2:$A},"SELECT Col2 WHERE COL2<>'' ORDER BY Col1 ",0)
Same but wrapped by unique.
=UNIQUE(QUERY({RANDARRAY(ROWS($A$2:$A)),$A$2:$A},"SELECT Col2 WHERE COL2<>'' ORDER BY Col1 ",0))
Hope it helps someone, even if years later. :)
Matt

Sum different unknown values from multiple tables in Google Spreadsheet

I'm having the following Issue and don't get the right formula. I don't even know, if it is possible.
I'm having three tables with different values. I want to calculate and sum up, which value appears how many times in all three tables. I don't really know the value when starting the process, so it should count the following: How often are which values shown in the tables.
Find a example of the problem here
so, the result should tell me, that overall, there are 3 values (a,b,c) and each value has a total quantity of 60.
Here, you'll find the result I'm looking for
I want to do that calculation with google spreadsheet, but I really don't get any solution.
Can somebody help? Thank you already in advance.
Try to use query function:
=QUERY({'Sheet1'!A1:B;'Sheet2'!A2:B;'Sheet3'!A2:B},"select Col2, sum(Col1) group by Col2")

Average calories of "moderate" food

I keep a spreadsheet with caloric information about food. Each row represents a product labelled as {negative, small, moderate} and the number of calories.
I included a shared copy of the spreadsheet.
Table
Shared table
I would like to calculate the average of the numbers that are in the same row as the keyword 'moderate'. For instance, I would like to obtain something like (890+914+731+1159+789)/5=897. I have tried =AVERAGE(B3,B7:B10) and it works but it needs to be modified when I add another product.
The expected output is in red. I want to obtain such output using formulas.
Thanks in advance
Maybe you can also consider the use of AVERAGEIF() as it seems the function is built for situations like this:
=averageif(A2:A; "moderate"; B2:B)
When you insert new row, formula will be modified automatically. Also, your formula is wrong, missing semicolon:
=AVERAGE(B3; B7:B10)
^
You can Use a IF Statement. Then you automatically do the average of the numbers IF the respective value is moderate. This is better, because it will work, if you have 5 or 5000 Moderates
Just use: =AVERAGE(FILTER(B2:B10;(A2:A10="moderate")))
You could also use SUMIF with COUNTIF, it's a more basic formula, not as powerful as FILTER, but just as funcitonal. Also to use unlimited ROWs, you can remove the number on the second part of the RANGE, this for any formula, in this case your formula would be as such:
=SUMIF(A2:A;"moderate";B2:B)/COUNTIF(A2:A;"moderate")

Resources