Alternative to pivot tables - google-sheets

This may seem a bit odd
But I'm trying to think of a way to make a pivot table using a single row across multiple columns.
Rather than having multiple items vertically and amounts in an adjacent column I was wanting to have several columns side by side in a single row in the order of item, amount, item, amount, etc. then total when the items are identical.
So in some columns there would be recurring items where I would like to sum the amount.
The concept is to create unique shopping lists for my nutrition clients.
I have new clients signing up so I was thinking an array formula with a sum function using unique function to aggregate ingredients.
But I can't think of a way to have this behave like a pivot table where it will automatically total items without it being in a single table.
Is what I'm suggesting possible?

Related

Google Sheets: Many to Many Table Join

I am trying to create a sheet to determine the amount of overlapping hours for employees.
I have one table with timeclock data for the Employees.
Table 1
And another with timeclock data for their Support Staff.
Table 2
This is the desired output. Each row from table A has all the date matches from table B. From here I would compute the number of overlapping hours in the final column and then roll that up into another sheet.
Table 3, Desired Output
(apologies for image links, I can't post inline images yet)
Sample sheet here Please let me know if you have any ideas for me!
I know its a combination of QUERY, ARRAYFORMULA, FILTER and more but I just can't find the right combo.
Here's a way of doing this type of join using only built-in functions:
=arrayformula(lambda(employee,support,
lambda(datecomp,
lambda(rows,
{vlookup(index(rows,,1),{row(employee),employee},sequence(1,columns(employee),2),false),
vlookup(index(rows,,2),{row(support),support},sequence(1,columns(support),2),false)})(
split(filter(datecomp,datecomp<>""),"|")))(
flatten(if(index(employee,,1)=transpose(index(support,,1)),row(employee)&"|"&transpose(row(support)),))))(
Employee!A1:D6,Support!A1:E5))
There's a lot going on here, but the basic idea is that we are comparing the date columns of each table against each other in a 2D IF array, and where the dates match we are obtaining the row index of each table. After some manipulations we can use these row indexes on each table in two side-by-side VLOOKUPs to obtain the joined table.
DMac,
I wrote myself a QUERY replacement custom function that uses real SQL select syntax.
For your data it looks something like (You need a tab called employee and a tab called support for this to work) :
=gsSQL("select * from employee full join support on employee.date = support.date")
See my test worksheet: (line 164 on gsSqlTest sheet)
https://docs.google.com/spreadsheets/d/1Zmyk7a7u0xvICrxen-c0CdpssrLTkHwYx6XL00Tb1ws/edit?usp=sharing
You need to add one Apps Script file to your sheet to give you the custom function:
https://github.com/demmings/gsSQL/blob/main/dist/gssql.js
For more help using more features see:
https://github.com/demmings/gsSQL
For example, changing the column titles, it would be like:
select employee.name as name .... (rest of your select).

How can I have multiple pivot tables in same sheet?

I have a big sheet with quite a lot of info that keeps growing over time. Based on that, I have created several pivot tables that do some calculations and rankings.
Every ranking keeps growing, so pivot tables may contain 10 rows now, but can grow up to 20 or 30 rows.
I managed to insert several pivot tables in the same sheet and now it looks well, with every ranking after the next one. However, if I add multiple rows, the pivot tables grow and start overlapping, so after a while the ones below start disappearing in favour of the first ones.
Is there a way to have multiple pivot tables in the same sheet with a fixed number of rows among them, preventing them from overlapping?
If you want to 'play' with the data, I created a sample in https://docs.google.com/spreadsheets/d/1MVX3tp6GIqVX6hTyk6TsCxV7YngiMpi7E8oSxa7a9ck/edit?usp=sharing. It is just a ranking on races, where I want to track the best times on different legs. Then it has a second sheet 'rankings' in which I have different pivot tables, one for each leg.
HOw's this for a single formula solution that will scale infinitely in users or legs:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(results!A2:A&"|Best of "&results!D1:1&"|"&OFFSET(results!D2,,,ROWS(results!D2:D),COLUMNS(results!D1:1))),"|",0,0),"Select Col2,Col1,MIN(Col3) where Col1<>'' and Col2<>'Best of ' group by Col1,Col2 order by Col2, MIN(Col3) label MIN(Col3)'Best', Col1'User',Col2''"))
You'll find it in cell B1 on the new tab in your sample called MK.Idea
I should mention that FLATTEN() is an undocumented function that I only recently discovered. I've believe it is intended to remain "hidden" in the back end of the sheets programming, but if what I did is what you're after, there really isn't a more efficient way to do it. I've spoken with an engineer at Google who was surprised it existed as well and told me there were no plans to deprecate it, so here's hoping! For a demo of what it does generally, you can see my sample here:
https://docs.google.com/spreadsheets/d/196NDPUZ-p2sPiiiYlYsJeHD6F_eJq7CWO_hP7rFqGpc/edit?usp=sharing
Spreadsheets and Pivot Tables are marvelous tools for data analysis but they aren't too friendly for creating reports and dashboards, if you are open, to recommendations try Google Data Studio (it includes pivot tables too --> https://support.google.com/datastudio/answer/7516660?hl=en)
Let say that you don't have time to learn another app or you just prefer to keep using spreadsheets, in this case it will be required to implement a workaround.
First, bear in mind that Pivot Tables don't actually overlap, instead an error message is shown:
Solution: insert some rows/columns to give enough room to the Pivot Table to be expanded.
NOTE: You could do this in advance by including a "safe zone" (meaning blank rows /columns) around the pivot tables. You could hide/unhide this "safe zone" as needed.
If you don't want to do the above manually, I think that it should be possible to use an on edit trigger of Google Apps Script to detect that pivot tables are shown and insert new rows/columns to avoid this. If the Pivot Table top left cell returns #REF! your script could use a do.. while or a while to insert the required rows or columns. An smart algorithm will read the Pivot Table settings to calculate the required rows and columns and then insert the required rows / columns in one pass.
Related
Pivot table with Google Script

Display columns of information in Google Sheets based on Drop down selection

What I am looking to do is have a list of items in a dropdown list in cell A1. Lets say the list is "Presidents, Movie Stars, Rappers".
When I select Presidents I want Column B in Sheet 1 to list all the presidents with column C listing their party they represented and column D to list their years in office. When I select Movie stars I want column B to List various Movie Star names, Column C to list number of movies starred in and Column D to display their highest paid film.
So in short I want 1 dropdown to populate 3 columns worth of data.
Everything I have looked up uses scripts(which I think this is completely doable without using) uses VLOOKUP but has 1 cell worth of data appear(ex, A1 dropdown displays data in A2 but not data in B1:B50, C1:C50, and D1:D50) or doesnt worth with multiple columns of data. I am fine if the data pulls from another sheet I just think there is a better way to do this then filling in 200+ cells with an if:then function based on my selection in cell A1. Anyone know an easy way to do this?
An elegant solution, in my opinion, is to do something like the following:
Create a column (which you can later hide) that has all value combinations, with a delimiter between the values. For example, you could have "Presidents>Barack Obama>Democrat>2008-2016"
Then create a simple function (no VLOOKUP needed!) to pull the individual values by using FIND to findn the location of the delimiters and split the combination.

PowerBI counts rows in non related table including filtering and non-matches

I have two tables in PowerBI and a slicer, presented below in an abstracted way.
I want to know the number of orders placed for a customer in a given date range. This data is a sample for illustration - there are actually around 10,000 Customers and 500,000 Orders and both tables have many other fields, Ids etc.
My challenge -
Whilst this is easy enough do by relating the tables and doing a count, the difficulty comes in when I still want to see customers with 0 orders and on top of that I want this to work within a date range. In other words, instead of the customers with no orders disappearing form the list, I want them to appear in the list, but with a 0 value, depending on the date range. It would also be good if this could act as a measure, so I can see the number of total customers that have not ordered on a month by month basis. I have tried outer joins, merge queries, cross joins and lookups and cant seem to crack it.
Example 1: If I set the order date slicer to be: 02/01/2017 to 01/01/2018 I want the following results
Example 2: If I set the order date slicer to be: 03/01/2017 to 06/01/2017 I want the following results
Any help appreciated!
Thanks
This is entirely possible with a Measure. When you're using the Order field to count the rows for each customer, you're essential doing a COUNTROWS() function.
With your relationship still active, we can Prefix this in a measure to check for the blanks, and in those cases, return 0. something like this would work
Measure = IF(ISBLANK(COUNTROWS(Orders)),0,COUNTROWS(Orders))
In this case, 'Orders' is the table containing the Order and Order Date fields

How to group a column of data based on rows

I have ~10000 rows in a spreadsheet and the first column (A) has a certain ID that I would like to group by. As an example, A2:A20 has the same ID, then A21:A31 has a different ID, A32:A55 has a different ID and so on, down to the bottom row.
I've tried using the Group button in Excel but I can't seem to get what I need. I'm looking to make separate row groups for the column ranges I specified above all the way to the bottom of the spreadsheet. Since I have ~10000 rows, I was looking for a way to not do the grouping manually.
Any way to do this?
Try using SUBTOTAL option. Using this the data is automatically grouped with subtotal options.

Resources