Listing the top value of rows based on a certain value in google spreadsheets - google-sheets-api

I have the following excel DPS table(s) all listed below eachother:
Column A Column B Column C
Parse Name DPS
61 Arlisk 991.7
46 Tritla 913.9
Parse Name DPS
79 Arlisk 1156.3
87 Lucija 1090.8
I have another name-table, which simply lists the names Arlisk, Tritla and Lucija.
Now I want to add another column to the name-table that shows the highest value found in column D of the other table of all rows that refer to the name of that row.
In other words the new table should list each name's highest DPS found across all the other tables.
I found the following, but the formula is wrong and Im not familiara enough with it to fix it further.
=ArrayFormula(MAX(IFERROR(INDEX($C$4:$C$999 ,SMALL(IF($B$4:$B$999=$B$4 ,ROW($B$4:$B$999)-ROW($B$4)+1),ROWS($B$4:$B4))),"")))
Could anyone give me some advice on the solution?

You want to get max DPS per name across all tables?
Given that those tables are in the same columns, then FILTER and MAX can give you the max DPS per name.
Formula:
=max(filter(C:C, B:B=E2))
Output:
You could also use the formula below to create a separate table. This will automatically list the unique names together with the max DPS based on the tables available in the range.
=query({B2:C}, "select Col1, max(Col2) where Col1 is not null and Col2 is not null group by Col1")
Output:

Related

QUERY - GROUP BY counting different clients by date

Data sample:
https://docs.google.com/spreadsheets/d/1DDs2PvljSsY0jD0v2VmM0NsGkJmhoBPKOXvln9d1MTw/edit?usp=sharing
Above is a link to a spreadsheet where I have a sample of the data I'm working with.
I need to do a query where i can count how many different clients I attended that day. Example (INFO column not needed as a result, just a helper here for me to describe what I need):
DATE
COUNT(DIFFERENT CLIENTS)
INFO
05/01/2021
3
"Fleury Campinas", "SEDI II AME SOROCABA", "Hospital Santa Catarina"
06/01/2021
2
"Hospital e Maternidade Metropolitano Lapa", "Fleury A+ Morumbi"
Can you help me?
Given the layout of the actual data and the locale of Brazil, I added a new sheet ("Erik Help") with this formula:
=ArrayFormula({"DATE"\"UNIQUE CLIENTS"\"INFO";{QUERY(UNIQUE({'Query from Data'!B5:B\'Query from Data'!E5:E});"Select Col1, COUNT(Col2) WHERE Col1 Is Not Null GROUP BY Col1 LABEL COUNT(Col2) ''")\REGEXREPLACE(REGEXREPLACE(TRIM(FLATTEN(QUERY(QUERY({'Query from Data'!B5:B\'Query from Data'!E5:E&","}; "Select MAX(Col2) WHERE Col1 Is Not Null GROUP BY Col2 PIVOT Col1");; 9^9)));"^\S+\s*|[,\s]+$";"");",\s*";CHAR(10))}})
This is complex, and explaining it in full would take far longer than writing it. So I am offering it as-is, inviting anyone who is interested to take it apart and see what each part does alone and collectively.
The short version:
Headers are created.
Under those, there is a virtual array formed of a two-column QUERY to the left of another one-column QUERY. The first returns unique dates and counts of unique clients (two columns). The second combines each date with the unique client list for that date and then uses REGEX-type commands to get rid of the date portion and to replace comma-space with a line return CHAR(10).
Try getting the unique values in the first and third columns then grouping by date using a query:
=query(unique({A:A,C:C}),"select Col1,count(Col2) where Col1 is not null group by Col1")

How to combine a row of cells in VBA if certain column values are the same

I have a database where all of the input from the user (through a userform) gets stored. In the database, each column is a different category for the type of data (ex. date, shift, quantity, etc) and the data from the userform input gets put into its corresponding category. For some of the data, all the data is the same except for the quantity. I was wondering how I could combine these rows into one and add the quantities to each other for the whole database (ex. combining the first and third data entries). I have tried playing around with a couple different loops but can't seem to figure anything out.
Period Date Line Shift Type Quantity
4 x 2 4/3/18 A 3 14 18
4 x 2 4/3/18 A 3 13 12
4 x 2 4/3/18 A 3 14 15
Thank you!
If you're looking to modify the underlying database, you might be able to query the data into the format you want by including all the other columns in a GROUP BY statement, save the result to another table, then replace the original table with the properly formatted one.
If you have the data in Excel and you just want to view it with the duplicate rows summed, a Pivot Table would be a good choice. You can select all the other columns as rows for the Pivot Table and sum of Quantity as the values.

Average Distinct Values in a single column in Power Pivot

I have a column in PowerPivot that basically goes:
1
1
2
3
4
3
5
4
If I =AVERAGE([Column]), it's going to average all 8 values in the sample column. I just need the average of the distinct values (i.e., in the example above I want the average of (1,2,3,4,5).
Any thoughts on how to go about doing this? I tried a combination of =(DISTINCT(AVERAGE)) but it gives a formula error.
Thanks!!
Kevin
There must be a cleaner way of doing this but here is one method which uses a measure to get the sum of the values divided by the number of times it appears (to basically give the original value) then uses an iterative function to do it for each unique value.
Apologies for the uninspired measure names:
[m1] = SUM(table1[theValue]) / COUNTROWS(Table1)
[m2] = AVERAGEX(VALUES(Tables1[theValue]), [m1])
Assuming your table is caled table1 and the column is called theValue

DAX - selecting rows with partial match

I have a powerpivot table that contains 2 columns:
Column 1 contains strings.
Column 2 contains comma delimited strings.
I would like to be able to display all the rows from column 1 when rows from column 2 contains the selection from a filter or slicer. For example:
String Values
ABCD A,A,B
EFGH A,C
if A is selected I would display both rows, if B is selected I would display only row 1...etc.
I know I can split the records - but this is not practical for me - the above is only the top of the iceberg. VBA is out of the question since this will published in SharePoint. Anybody has an idea on how I could do that ? Thanks.
I found the solution in a blog from Javier Guillem:
http://javierguillen.wordpress.com/2012/02/10/simulating-an-approximate-match-vlookup-in-powerpivot/
If in my example the name of the table is "facts", I create a second unlinked table called dimRef that I populate with all possible values that I am interested to match: A,B,C,D...etc.
Then I define the measure M as:
M:=If ( Hasonevalue(facts[Values] ),
Calculate (
LASTNONBLANK (dimRef[String], 1 ),
Filter ( dimRef, SEARCH(dimRef[String],Values(facts[String]),1,0) > 0 )
)
)
I can then use the string column of the facts table and the measure in a pivot table and use dimRef as a selector. If filters the row as per the selection.
One small detail: the measure is not available in PowerView...Anybody knows why ?

How to add two columns with the same names from different Tables

How to add two cloumns with the same name from different tables. It needs to be dymanic, because i have columns based on months. Below is the sample data. which i would use to calculate the moving 12 month average for attrition.
Transferout Oct'11 Nov'11
3310ED
3310FL
3310HD 1
3310PZ
3310RC
3310SH
3310SM 1
Terinations Oct'11 Nov'11
3310ED
3310FL
3310HD 1
3310PZ 1
3310RC
So according to the column name and dept id in the row filed the above two tables needs to be added and later divided by the head count of the respective dept ids using the same column headings in a diff table
Looks like you can use the LOOKUPVALUE function or the RELATED function (if the tables are related).