TABLEAU - Joins on the fly on raw data - join

I have been trying to perform joins on the fly in Tableau to perform some online computation - with no luck so far.
I wonder if any of you is aware of a way to achieve this?
I have a typical transactions dataset ("MYDATA"), with user ID (user's identifier), transaction date (when the transaction occurred), and purchases (the transactions). Something like:
ID TRANSACTION DATE PURCHASES
123 20/03/2020 1
123 22/03/2020 4
234 20/03/2020 10
234 22/03/2020 1
345 22/03/2020 5
What I would like to achieve is to add to it a variable with the SUM of PURCHASES by ID (say field "PURCHASES PER ID").
Then, critically, I'd like to make this computation update dynamically as I filter by different values in TRANSACTION DATE from the UI.
Ultimately I'd like to create a chart displaying the count of users (field "ID") in each value of the field "PURCHASES PER ID" (like bins), where "PURCHASES PER ID" is re-computed according to the date ranges selected in the worksheet.
Something like:
Case 1 : FILTER Transaction date = 20/03/2020 AND 22/03/2020
|---------------------|------------------|
| count OF ID | SUM of PURCHASES |
|---------------------|------------------|
| 2 | 5 |
|---------------------|------------------|
| 1 | 11 |
|---------------------|------------------|
Case 2 : FILTER Transaction date = 20/03/2020
|---------------------|------------------|
| count OF ID | SUM of PURCHASES |
|---------------------|------------------|
| 1 | 1 |
|---------------------|------------------|
| 1 | 10 |
|---------------------|------------------|
I'd expect this to be doable in Tableau, as I'm able to it with a much more simple (and cheaper) tool like Google Data Studio.
In Data Studio I'd simply do a join between "MYDATA" and the sum of PURCHASES grouped by ID - using ID as KEY. Then, I'd able to use that calculated sum of purchases as a dimension, and count the IDs in it.
Are you aware of a way to achieve the same in Tableau?
Many thanks

Think I got it.
My solution was:
Columns: ({FIXED [ID]: SUM([PURCHASES])})
Rows: CNTD(ID)
Filters: Add TRANSACTION DATE to Context
This allows me to achieve the view I wanted to.

Related

Sorting data on google sheets

Looking for a bit of help creating a small database for orders.
So currently I'm parsing orders I receive to a order list on google sheets.
I have a few columns like customer name, date, reference number, address, etc.
Trying to have 1 main order sheet with all parsed orders, then have orders sorted by month in separate sheets and removing duplicate order entries.
You can write the script in given documentation for removing duplicates:
https://developers.google.com/apps-script/articles/removing_duplicates?hl=zh-TW
And For sorting of order:
var ss = SpreadsheetApp.getActiveSpreadsheet();//create object for google spreadsheet.
var timeSheet= ss.getSheetByName("sheetName");//create object for particuler sheet
var timeSheetLastRow = timeSheet.getLastRow();
timeSheet.getRange("A3:BC"+timeSheetLastRow).sort(7);// 7 is column number
You can try those things merge code for your sheet.
Let's create a dummy data that matches your content in Google Sheet.
A | B | C | D
-------------------------------------------------------
customer name | date | reference number | address
ABC | 1-1-1990 | 00100 | Home Towm
EFG | 3-2-1991 | 00200 | Farm Towm
HIJ | 2-3-1990 | 00300 | Your Towm
ABC | 1-1-1990 | 00100 | Home Towm
Let's assume the data above is added manually, and there is another sheet in the same SpreadSheet where sorted & unique data will be added from above sheet.
Formula: Unique(Sort('Sheet Name'!A:D, sort_column, is_ascending))
Example: Unique(Sort('Sheet Name'!A:D, 2, True))

Can I modify one spreadsheet document (google sheets) based on information from a separate spreadsheet

Not sure if this is the best place to ask about spreadsheets, but here goes:
I'm trying to help someone modify information on one spreadsheet document when information on a separate spreadsheet document is modified (without coding a solution from scratch using the sheetsAPI).
For example, my client has a product database stored in a spreadsheet document, products, when a customer places an order on the clients website, a separate spreadsheet document, openOrders, is updated using the sheetsAPI and some server code. When this document is updated, I'd like to subtract the quantity of items being ordered, from the quantity of the item (or items) available being listed in products. I'm wondering if letting these spreadsheet documents "speak" to each other is possible without coding a solution server-side using the API.
products looks kind of like this:
Product Name | Units | Unit Price
---------------------------------
Product 1 | 6 | 1600
Product 2 | 3 | 1200
Product 3 | 17 | 400
Product 4 | 2 | 600
openOrders looks kind of like this:
Product Ordered | Units | Unit Price | Total
--------------------------------------------
Product 3 | 1 | 400 | 400
Product 2 | 2 | 1200 | 2400
Product 3 | 5 | 400 | 2000
Product 1 | 1 | 1600 | 1600
When the openOrders sheet is updated with a new order, I'd like to subtract the number of Units ordered, from the number of Units available in products. Keep in mind these are two separate spreadsheet documents. I am new to spreadsheets so this is all very foreign to me, it could be possible that I'm using the spreadsheets in a fundamentally incorrect way, and I'm open to that possibility.
you can do:
=ARRAYFORMULA(QUERY({A2:A, B2:B*-1;
IMPORTRANGE("ID_of_spreadsheet", "Sheet1!A2:B")},
"select sum(Col2) where Col1 <> '' group by Col1 label sum(Col2)''", 0)*-1)

How can I perform the same operation on all cells in a row?

I am trying to calculate the cost of products based on the amount of products sold (in one row) and the cost of each item (in another row).
I have written a simple formula, but every time I add or remove columns, it must be manually adjusted.
=IF(COUNT(E4:AC4)>0,(E4*$E$3+F4*$F$3+G4*$G$3+H4*$H$3+I4*$I$3+J4*$J$3+K4*$K$3+L4*$L$3+M4*$M$3+N4*$N$3+O4*$O$3+P4*$P$3+Q4*$Q$3+R4*$R$3+S4*$S$3+T4*$T$3+U4*$U$3+V4*$V$3+W4*$W$3+X4*$X$3+Y4*$Y$3+Z4*$Z$3+AA4*$AA$3+AB4*$AB$3+AC4*$AC$29), "")
This is an example of a problem best solved by ARRAYFORMULA
Take the table
______|_$5_|_$7_|_$2_|_$3_|_$5_|__TOTAL__
-----------------------------------------
Bob | | 2 | | 1 | | ?
-----------------------------------------
Alice | | | 2 | | | ?
-----------------------------------------
Eve | 1 | | 1 | | 3 | ?
How do we solve the total cost for each row?
In the total column for Bob's row (2), simply invoking
=SUM(ARRAYFORMULA(B2:F2*B$1:F$1))
Will accurately give us his total cost; $7*2 + $3*1 = $17.
Specifically, ARRAYFORMULA(B2:F2*B$1:F$1) will give us a range composed of B2*B1 | C2 * C1 | D2 * D1 ..., which you could use e.g. in line below Bob's order to show the price breakdown by item. SUM() adds those numbers together. You could further add to this formula to add taxes, gratuity, shipping, service fees, etc.
Now that we have this formula, we can simply copy this down the column into each new row in the 'Total' column.
When a new column is inserted to the left, the formula will be automatically adjusted by the spreadsheet to be the new range.

Is it possible to aggregate expenses per category in google spreadsheets

I am trying to track my expenses manually. I looked for already built options and I did not find anyone I knew how to use or that it covered what I want to do.
What I am doing is basically manually write down what appears in my bank, with the intention of categorizing the expenses myself, since as I said, I did not find a better way to do it.
So it looks like this:
Cinema | 11.95
Going out (restaurant1) | 26.55
Netflix | 13.95
Weekly purchases | 72.66
Going out | 9
Bill (type) | 29.16
Rent month | 650
Going out | 26.55
Bill (type2) | 66.45
Compra semanal | 81.09
Bill (type3) | 21.1
( "|" is used as if it were two different cells) And what I would like now is to take the generic name that I gave the cathegory (without the parenthesis, I am using those for myself, so I can track where was the money spent, more specifically), and how much was spent.
In programming I would do this with a regex for the left cell, and aggregating by name, and then plotting the data somehow. I am unsure if this is even possible, maybe I should use Excel but Drive has the cloud advantage so I would like some help as to where to start, I do not need anything too fancy, a new column with the category and the total spent would work wonders for me, but I have not found an easy way of doing it (and I doubt I am doing something so complex, so I assume I am thinking this the wrong way). Best case scenario, I manage to plot it all so it is more visual, or I can have several columns plotted against each other (I have different columns for shared expenses, personal expenses, and so on).
If you can put the category (e.g. Bill) in a separate column from your details (e.g. type 1) then the Pivot Table feature is exactly what you need.
Start with something like this (the heading on each column is important):
Category | Details | Amount
Cinema | | 11.95
Going out | restaurant 1 | 26.55
Netflix | | 13.95
Weekly purchases | | 72.66
Going out | | 9
Bill | type | 29.16
Rent month | | 650
Going out | | 26.55
Bill | type2 | 66.45
Compra semanal | | 81.09
Bill | type3 | 21.1
Then click Data, Pivot Table. Under Rows, click Add and choose Category. Under Values, click Add and choose Amount. You should see a table like this:
Category | SUM of Amount
Bill| 116.71
Cinema | 11.95
Compra semanal | 81.09
Going out | 62.1
Netflix | 13.95
Rent month | 650
Weekly purchases | 72.66
Grand Total | 1008.46
Any unique value in the Category column creates a new row in the pivot table.
Further Details: https://support.google.com/docs/answer/1272900
=ARRAYFORMULA(QUERY({REGEXREPLACE(TRIM(A:A)," \(.*\)",),B:B},"Select Col1,sum(Col2) where Col1 is not null group by Col1"))

correlate a demographic column with answers from multiple columns

I have a spreadsheet from a Google Consumer Survey. The survey captured demographics as well as the responses to a question. Acceptable responses could have chosen zero or more 'answers'. The response for each answer is in a unique column. For example,
user id | gender | age | income | answer 1 | answer 2 | answer 3 |
0001 | Female | 20-30 | 50-75 | [empty] | Right | Never |
0002 | Male | 20-30 | 30-50 | Up | Left | [empty] |
I would like to know how to correlate a column of demographic info with each of the possible answers. For example, I want to be able to answer questions like, Were males more likely than females to choose X for answer 1? and Which age group was more likely to choose Y for answer 2?
I prefer an answer using Google Sheets functions, but I am open to learning other ways to understand the data. Thank you for any help!
Good way is to use query function. Let's first assume, your data is stored in range A:G:
A | B | C | D | E | F | G |
user id | gender | age | income | answer 1 | answer 2 | answer 3 |
0001 | Female |20-30| 50-75 | [empty] | Right | Never |
0002 | Male |20-30| 30-50 | Up | Left | [empty] |
you may write simple query functions.
For example, to count all answer 1, group them by gender and age, pivot by answer 1:
=query(A:G,"select B, C, count(D) where not A is null group by B, C pivot E")
where not A is null -- prevents empty data to be used in query
count(D) -- can count any column, that wasn't already used by query
group by B, C -- must contain all selected items, except aggregates (count, sum, ets.)
pivot E -- will make all answers to show in separate columns.
The result will look like this:
Left Never Right Up
Female 20-30 1 1 1
Female 30-40 1
Male 20-30 1 1 1
Male 30-40 1
Please, look at complete Query Language Reference to learn more.
Have you tried using the Pivot Table function of Google Sheets?
Download the data in excel format after the survey is complete and open with Google Sheets
Select the tab with the resulting data from the Google Consumer Survey after it is run.
From the menu, select Data -> Pivot Table. This opens a new tab in your spreadsheet.
For the Values area of the pivot table, select User ID and from the "Summerize by" dropdown, select COUNTUNIQUE
For the columns and rows, select whichever dimensions you are interested in. For instance, in your example, you would pick
"Gender" and "Answer 1" as a row and column.
"Age" and "Answer 2" as a row and column.
This should answer these kinds of questions easily.
Hope this helps!
What I think I needed was the COUNTIFS function (in Google Sheets). Notice the plural use, which is different than countif (singular).
COUNTIFS allowed me to specify multiple criteria to make a score for each demographic segment. For example, I could count all the Males that responded Up in the answer 1 column.

Resources