How to use a google sheets pivot query to output strings - sql

I have a (much larger) table like this sample:
I am trying to output a table that looks like this:
The closest I can get with a pivot query returns numerical results in the value fields, rather than the desired text strings
=query(Data, "Select D,count(D) group by D Pivot B")
I resorted to a series of formulas to build my row and column headers, and then fill in the data field - See Version 3 in the sample sheet. But I couldn't figure out how to fill in the data with a single formula - as opposed to copying and pasting in the data field, which is not desirable with a dynamic number of row and column headers based on the original data.
Is there a way to wrap my data field formula (in cell B44 of the sample) in an arrayformula that will fill the data field, with a dynamic number of columns and rows?
Or even more advanced is there a formula that will deliver my desired results table in a single formula?

This should work, it's a bit difficult to explain, but i could demonstrate the various parts if you opened up your sheet to editable...
=ARRAYFORMULA(TRANSPOSE(QUERY(TRIM(SPLIT(TRANSPOSE(QUERY(QUERY({CHAR(10)&A2:A11,B2:B11&"|"&D2:D11&"|"},"select MAX(Col1) group by Col1 pivot Col2"),,9^9)),"|",0,0)),"select Col1,MAX(Col3) where Col1<>'' group by Col1 pivot Col2 order by Col1 desc label Col1'Project'")))

Related

Google Sheets - Is it possible to use query to search for the data from the sheets that i select with dropdown list? If not, what can i do?

GoodDay everyone, recently I am trying to learn about using the Google Sheets. My question is same as the title, and these are some examples of the data.
The data from first sheet
The data from second sheet
I am trying to create a searching function in the main page in order to get some data by selecting a specific sheet.
And these are the result I expect to see.
By choosing option using the dropdown list, I expect the query or any other things will detect the option and display all the data I need from the sheet I have chosen.
RESULT EXPECTED 1
RESULT EXPECTED 2
RESULT EXPECTED 3
Is that even possible in Google Sheets?
use:
=INDEX(QUERY({
IFERROR(JACKIE!A4:A/0, "JACKIE"), JACKIE!A4:B;
IFERROR(KELVIN!A4:A/0, "KELVIN"), KELVIN!A4:B},
"where Col2 is not null
and Col1 = '"&B2&"'
and Col3 = '"&B3&"'", ))

Combine Rows but concatenate on a certain field in Excel Power Query or Microsoft SQL

I have brought a table from an Authority database into Excel via power query OBDC type, that includes fields like:
Date - various
Comments - mem_txt
Sequence - seq_num
The Comments field has a length restriction, and if a longer string is entered, it returns multiple rows with the Comments field being chopped into suitable lengths and the order returned in the Sequence field as per extract below. All other parts of the records are the same.
I want to collapse the rows based and concatenate the various Comments into a single entry. There is a date/time column just outside of the screen shot above that can be used to group the rows by (it is the same for the set of rows, but unique across the data set).
For example:
I did try bring the data in by a query connection, using the GROUP_CONCAT(Comments SEPARATOR ', ') and GROUP BY date, but that command isn't available in Microsoft Query.
Assuming the date/time column you refer to is named date_time, the M code would be:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
#"Grouped Rows" = Table.Group(
Source,
{"date_time"},
{{"NewCol", each Text.Combine([mem_text])}}
)
in
#"Grouped Rows"
Amend the Source line as required.

Pandas Pivot table : Get only the value counts and not columns

I am trying to make a pivot table with a data set with many columns.
When making a pivot table with code below I get all the columns which I don't want.
I only want the counts and not any other columns there. Can i achieve this ?
table1 = pd.pivot_table(dfCALCNoExcecption,index=['AD Platform','Agent Program'],columns=None,aggfunc='count')
The output of above code in excel output is like below( I have not pasted the whole as there are around 50 columns):
The Desired Output I am trying to get:
You can group by your data based on the columns 'AD Plataform' and 'Agent Program'. After that, you can sum all the values of the column that has the quantity of the machines. Here is my code:
df.groupby(['AD Plataform', 'Agent Program'])['AD Hostname'].sum()
This is not complete but a part of this can be achieved by Groupby. I am not sure how to rename the third column to "Count"
dfAgentTable3 = dfCALCNoExcecption.groupby(['AD Platform', 'Agent Program'])['AD Hostname'].count().sort_index(ascending=True)

VBA macro for excel. Mark row if cells in column A are the same but different in column C

I do not have any code yet as I dont know VBA that much or at all.
I got excell sheet with 4 columns. Column A is main group and C is subgroups within groups from column A.
i need to mark somehow rows where within same JobID, WFID is the same and where WFID is different within same JobID.
JobID TaskID WFID
39822 913914 Complete
39822 913915 no complete
37941 905439 Complete
37941 905440 Complete
Would you be able to help pleasE?
You do not really need macros to identify your rows.
Simply put this formula in a new column
=COUNTIFS($A$1:$A$8,A1,$C$1:$C$8,"<>"&C1)
Wherever there are different values in col C for same value of col A it will throw a 1 else 0
If you want to highlight, I recommend using conditional formatting based on the value of your new column with (0/1) values.
Hope this answers your query.

Excel: Selecting Specific Columns and Rows in Pivot Table and Formatting

I'm using a Pivot Table in Excel 2010, and while searching posts I find that a lot of users are frustrated like me because it doesn't keep all formats.
So what I'm trying to do is run a macro that formats columns in a Pivot table, but limited to the last row and column in the table. I have the formatting info, but I just need to know how to apply it to specific columns and rows.
What I was thinking might work is finding the last column of the Values row, in this case "Stops per Rte" which is the last Values column; however, I have months listed at the top, so it repeats across months. If the user filters only certain months then the # of columns will decrease.
Same goes for the # of rows: of course, the user should be able to expand/collapse rows as needed, so I only want the column format to go to the last row or just above "Grand Total", if possible.
Hopefully, this makes sense. Thanks in advance! = )