Union Vertical Blending in Data Studio - google-sheets

I want to blend several tables into 1 table. All of the tables have the same column so I'm thinking to UNION vertical all of the tables.
My data source is Google Sheets/ Spreadsheets.
The data will look like this:
Table1
| Type | Object | Amount |
|:---- |:---------:| ------:|
| Tech | PC | $100 |
| Tech | Keyboard | $50 |
| Tech | Mouse | $60 |
Table2
| Type | Object | Amount |
|:----- |:-----------------------:| ------:|
| Sales | Sales Incentives | $1000 |
| Sales | Meeting with Client | $400 |
| Sales | Visiting stores | $80 |
While the desired output would be:
| Type | Object | Amount |
|:----- |:-----------------------:| ------:|
| Sales | Sales Incentives | $1000 |
| Sales | Meeting with Client | $400 |
| Sales | Visiting stores | $80 |
| Tech | PC | $100 |
| Tech | Keyboard | $50 |
| Tech | Mouse | $60 |
If you can't see the table you can see the picture here
enter image description here
Anyone can help me with this? Thank you

I just got the the answer:
You can use the blending FULL OUTER JOIN and use the formula:
COALESCE(Name (Source #1),Name (Source #2),Name (Source #3))
You can see full information here
Thank you for Mehdi Oidjida for the help.

Related

Google Sheets Return Any(All) Row Value(s) For MAX-GROUP Query

I am looking to return non-grouped row values from a query of a table sorted by the MAX value of a column, within a group.
DATA TABLE
| NAME | ASSET | ACTION | DATE |
|--|--|--|--|
| JOE | CAR | BOUGHT | 1/1/2020 |
| JANE | HORSE | BOUGHT | 1/1/2021 |
| JOE | HORSE | BOUGHT | 2/1/2021 |
| JANE | HORSE | SOLD | 3/1/2021 |
| JOE | CAR | SOLD | 1/1/2022 |
| JOE | CAR | BOUGHT | 2/1/2022 |
For the table above, I presented the following code.
=QUERY(A1:D5,"SELECT A,B,C,D, MAX(D) GROUP BY A,B",TRUE)
The following TARGET TABLE is output I'm looking for:
| NAME | ASSET | ACTION | DATE |
|--|--|--|--|
| JANE | HORSE | SOLD | 3/1/2021 |
| JOE | HORSE | BOUGHT | 2/1/2021 |
| JOE | CAR | BOUGHT | 2/1/2022 |
However, because 'C' is not included in the GROUP, the formula returns an error. "Unable to parse query string for Function QUERY parameter 2: ADD_COL_TO_GROUP_BY_OR_AGG: C"
If I were to omit COL C & D, "ACTION" & "DATE" from the SELECT: =QUERY(A1:D5,"SELECT A,B, MAX(D) GROUP BY A,B",TRUE) , I have the correct record rows, but am missing the STATUS.
MAX-DATE TABLE
| NAME | ASSET | max DATE |
|--|--|--|
| JANE | HORSE | 3/1/2021 |
| JOE | HORSE | 2/1/2021 |
| JOE | CAR | 2/1/2022 |
OR, when I add COL C as a "PIVIOT": =QUERY(A1:D5,"SELECT A,B, MAX(D) GROUP BY A,B PIVOT C",TRUE)I have the correct record rows, but do not have the 'current' STATUS within the record row.
PIVOT ACTION TABLE
| NAME | ASSET | BOUGHT | SOLD |
|--|--|--|--|
| JANE | HORSE | 1/1/2021 | 3/1/2021 |
| JOE | HORSE | 2/1/2021 | |
| JOE | CAR | 2/1/2022 | 1/1/2022 |
Still I have not found a method to create my TARGET TABLE.
Am I overlooking a method to include a non-grouped field into a query using MAX()? Or is it impossible within Google Sheets Query without JOIN functions?
(I hope it is obvious that I desire to apply this to a large and dynamic dataset.)
Thank you for your insight. Cheers!
It's not that flexible to work with QUERYs with its aggregation requisites and so on.
You can create a filter, by comparing column D with a "fictional" column created with BYROW: = BYROW(A2:A,LAMBDA(each,MAXIFS($D$2:$D,$A$2:$A,each,$B$2:$B,OFFSET(each,,1))))
That would look like this (I highlighted the matches and added extra rows for reference):
Then, you can set this filter (don't create this column, it's just a visualization of what I did):
=FILTER(A2:D,D2:D = BYROW(A2:A,LAMBDA(each,MAXIFS($D$2:$D,$A$2:$A,each,$B$2:$B,OFFSET(each,,1)))))
This way, you're comparing the dates with the maximum for each category

How to prevent rows from shifting when syncing with main data source?

I am creating a directory of people in a group. In the first sheet are the names, address, phone, and email info. The basics.
Then in Sheet 2 I am keeping a record of attendance.
In the third sheet I am keeping a record of some goals that are accomplished.
I used =ARRAYFORMULA(BASE!A:A) to get the first column and put that in the second and third sheets.
This worked great for a while. Then we got a new member. I added their info to the base sheet. His name was brought over to the second and third sheet. That's good. But it didn't keep the rows connected on the second and third sheet. They were off by one row since adding the new member shifted the cells that he was added on.
SO...
Base Sheet
|--------------|------------|------------|------------------|
|First Name | Last Name | Address | and so on...... |
|--------------|------------|------------|------------------|
|John | Doe | 123 Main | |
|--------------|------------|------------|------------------|
|Jim | Smith | 123 Elm | |
|--------------|------------|------------|------------------|
|Jill | Summers | 123 Aspen | |
|--------------|------------|------------|------------------|
Then I have another sheet for tracking attendance taking the first name and last name from the base sheet.
The top row and first two columns are frozen on both sheets.
|--------------|------------|------------|---------|---------------|
| First Name | Last Name | 10/1/19 | 10/7/19 | and so on.....|
|--------------|------------|------------|---------|---------------|
| John | Doe | x | x | |
|--------------|------------|------------|---------|---------------|
| Jim | Smith | | x | |
|--------------|------------|------------|---------|---------------|
| Jill | Summers | x | | |
|--------------|------------|------------|---------|---------------|
What I would like to do is be able to add a new row for a new name and it create a new row in the secondary sheets as well. For example...
|--------------|------------|------------|------------------|
|First Name | Last Name | Address | and so on...... |
|--------------|------------|------------|------------------|
|John | Doe | 123 Main | |
|--------------|------------|------------|------------------|
|Julie | Fry | 123 Oak | |
|--------------|------------|------------|------------------|
|Jim | Smith | 123 Elm | |
|--------------|------------|------------|------------------|
|Jill | Summers | 123 Aspen | |
|--------------|------------|------------|------------------|
which would result in ...
|--------------|------------|------------|---------|---------------|
| First Name | Last Name | 10/1/19 | 10/7/19 | and so on.....|
|--------------|------------|------------|---------|---------------|
| John | Doe | x | x | |
|--------------|------------|------------|---------|---------------|
| Julie | Fry | | | |
|--------------|------------|------------|---------|---------------|
| Jim | Smith | | x | |
|--------------|------------|------------|---------|---------------|
| Jill | Summers | x | | |
|--------------|------------|------------|---------|---------------|
Is there a way to fix this situation? Or perhaps just a better way to do this?
I know I could add the name to the bottom of the list and that would "kinda" work, but then I wouldn't be able to sort by first of last name. The sort would work on the base page, but it would also sort the name on the attendance page, but the data in the rows would be unaffected.
you can try to lock it down with INDIRECT like:
=ARRAYFORMULA(INDIRECT("BASE!B:B"))

Time span accumulating fact tables design

I need to design a star schema to process order processing. The progress of an order look like this:
Customer C place an order on item I with quantity 100
Factory F1 take the order partially with quantity 30
Factory F2 take the order partially with quantity 20
Buy from market 50 items
F1 delivery 20 items
F1 delivery 7 items
F1 cancel the contract (we need to buy 3 more item from market)
F2 delivery 20 items
Buy from market 3 items
Complete the order
How can I design a fact table in this case, since the number of step is not fixed, the data types of event is not the same.
I'm sorry for my bad English.
The definition of an Accumulating Snapshot Fact table according to Kimball is:
summarizes the measurement events occurring at predictable steps between the beginning and the end of a process.
For this particular use case I would go with a Transaction Fact Table as the events (steps) are unpredictable, it is more like an event fact table, something similar to logs or audits.
| order_key | date_key | full_datetime | entity_key (customer, factory, etc. varchar) | entity_type | state | quantity |
|-----------|----------|---------------------|----------------------------------------------|-------------|----------|----------|
| 1 | 20190602 | 2019-06-02 04:30:00 | C1 | customer | request | 100 |
| 1 | 20190602 | 2019-06-02 05:30:00 | F1 | factory | receive | 30 |
| 1 | 20190602 | 2019-06-02 05:30:00 | F2 | factory | receive | 20 |
| 1 | 20190602 | 2019-06-02 05:40:00 | Company? | company | buy | 50 |
| 1 | 20190603 | 2019-06-03 06:40:00 | F1 | factory | deliver | 20 |
| 1 | 20190603 | 2019-06-03 02:40:00 | F1 | factory | deliver | 7 |
| 1 | 20190603 | 2019-06-03 04:40:00 | F1 | factory | deliver | 3 |
| 1 | 20190603 | 2019-06-03 06:40:00 | F1 | factory | cancel | |
| 1 | 20190604 | 2019-06-04 07:40:00 | F2 | factory | deliver | 20 |
| 1 | 20190604 | 2019-06-04 07:40:00 | Company? | company | buy | 3 |
| 1 | 20190604 | 2019-06-04 09:40:00 | Company? | company | complete | 100 |
I'm not sure about your reporting needs as they were not specified, but assuming you need to measure lag/durations of unpredictable steps, you could PIVOT and use dynamic SQL to create the required view
SQL Server dynamic PIVOT query?
Let me know if you came up with something different as I'm interested on this particular use case. Good luck

Try to match string in column and print matching column name

I am trying to build an expense dashboard in google sheets for my personal use.
I have data that I will pull from my receipts like so:
First sheet: "Expenses Feb 18"
+------------+--------+--------+
| Item | Amount | Type |
+------------+--------+--------+
| Tomatoes | 2.39 | veggie |
| Joghurt | 1.45 | dairy |
| mozzarella | 1.99 | dairy |
| macadamia | 4.59 | nuts |
+------------+--------+--------+
Second table: "Categories"
+------------+----------+-----------+---------------+
| dairy | veggie | nuts | uncategorised |
+------------+----------+-----------+---------------+
| joghurt | tomatoes | macadamia | a |
| mozzarella | cucumber | pecan | b |
| feta | | | c |
| | | | d-z |
| | | | 0-9 |
| | | | - |
| | | | _ |
+------------+----------+-----------+---------------+
I want to automatically fill out the type column based on the item name.
So far I have a regex that is able to match an item. It will print the matched string. But what I need is the column name (header). And it has to be able to loop through the columns. This only works for a single column.
=REGEXEXTRACT(C11, JOIN("|", INDIRECT("Categories!A1:A"&COUNTA(Categories!A:A))))
The second table is not a desirable way to enter data. Data should be entered preferably with more rows than columns ( not in a pivoted manner).
=ARRAYFORMULA(CONCATENATE(IF(A16=$C$24:$E$25,C$23:E$23,)))
A16 : 🍅
C24:E25: Category table
C23:E23: Category header.

Rails Many to many relationships with connecting or cloning two table with references?

I'm a new with Rails and I'm having trouble with some types of associations that seem a bit more complex than the ones I've been exposed to so far.
Zombie_users Body_parts_status Body_parts
| id | name | | id | user_id | body_part_id | recovery | | id | name |
|-----------| --> |----------------------------------------| --> |---------------|
| 1 | Joe | | 1 | 1 | 2 | 10% | | 1 | left leg |
| 2 | Max | | 2 | 1 | 3 | 43% | | 2 | brain |
| 3 | hair |
| 4 | blue eye |
Zobmie_users Recovery_tools Body_parts_impacts
| id | name | | id |user_id| name | | id|recovery_tool_id| body_part_id | impact |
|-----------|-->|-------------------|-->|--------------------------------------------|
| 1 | Joe | | 1 | 1 |hammer| | 1 | 1 | 2 | 10% |
| 2 | Max | | 2 | 1 |magic | | 2 | 2 | 3 | 43% |
graphic illustration of the needed functionality
We have users and a list of body parts.
I need that the users will be able to create recovery tools with which they can through Body Parts impact recover their body parts status :)
and be able to check what part of the body still need to be fixed(compared to the list) and what body parts they have already corrected.
My problem is that I do not know how to implement such connections.
because I need to have some kind of clone of the body parts to body parts status for each user.
But how I reference it so it also works with Body Parts impacts
I do not have even a concept of where to start :)
body parts table is just a long listing of all the parts of the human body
and each user should have their own "copy" of all these parts.

Resources