Query with split in where clause - arrays

I'm trying to craft a Google Sheets query that outputs rows based on the left half of a split.
I'm using this in an employee status tracking sheet where my overview tab shows the last status update taken from the data tab (eventually)
This is what the overview tab will eventually look like. Note the number to the left of the employee name, I'm using this like an index.
This is where the data lives, there is an employee and multiple status updates. Note the numbers being used here as well. Each status update starts with the employee number "1" followed by a "-" then an incremental number.
It's easy enough to output all of the status updates, or a single status update, where I'm stuck is how to output only the updates that match the employee number.
=ArrayFormula(query({DataRange,to_text(DataRange)},"Select Col2, Col3, Col4 where Col2 ='"&"1-1"&"'",0))
Any ideas on how I can accomplish this?
-- or any suggestions for tacking this type of sheet in a different way?

try:
=ARRAYFORMULA(QUERY({DataRange, TO_TEXT(DataRange)},
"select Col2,Col3,Col4 where Col2 ='1-1'", 0))
and make sure that 1-1 is formatted as Plain text not Date

Related

Google Sheets: EXCLUDE hidden rows in query pulling unique data using indirect function

I have an Apps Script pulling every tab name in my Google Sheet into a list. I'm then using a Query to pull all unique Names (from a Name column) from each of those tabs, with the Indirect function.
There are currently hidden rows in each of the tabs (there are 15 tabs total). The Query I have is currently pulling the Names in those hidden tabs.
How do I tell the Query to pull all unique data EXCEPT the hidden rows? Here is the existing Query formula I have which is including hidden row data (I'm only including 2 tabs of data here to shorten the formula for this example):
=UNIQUE(QUERY({IF(B2="", {"","","",""}, INDIRECT(B2));IF(B3="", {"","","",""}, INDIRECT(B3))},"Select Col4 where Col4 is not null order by Col4 label Col4 'Names'",1))
The {"","","",""} is because I have INDIRECT formulas for future anticipated tabs which don't yet exist in the list of tabs, so I won't have to update the formula every time a new tab is added. For excluding the hidden data, I've looked into the SUBTOTAL formula but I'm having trouble applying it to this situation.
Here's a mock-up, smaller scale example of the sheet I'm working with. All of the names in the Names list on the Tabs tab that start with "Hidden" are in hidden rows on one of the tabs the query is pulling from. I want to exclude those Hidden names/rows from the query output.
Thanks in advance!
SUBTOTAL is the way but it does not work with arrayformula so you will need to drag it down into each row. see your sheet.
=UNIQUE(QUERY({
IF(B2="", {"","","","",""}, INDIRECT(B2));
IF(B3="", {"","","","",""}, INDIRECT(B3));
IF(B42="", {"","","","",""}, INDIRECT(B4))},
"Select Col4
where Col4 is not null
and Col5 = 1
order by Col4
label Col4 'Name'", 1))
also note the range change from A:D to A:E

Combining rows and columns of text using Sheets Queries

I'm trying to get to an array function that will select multiple rows and columns of data and present the data cleanly in a single cell. The data in the orange headed block has multiple rows (speakers) for each ID (sessions). The data in the blue block is the unique list of IDs (sessions) where I'm trying to get a formatted output. The ideal output would be (name) - (title) separated by cf/lf so multiple speakers will stack neatly in the same cell.
This gives an imperfect result with everything separated by dashes:
=TEXTJOIN(" - ",1,QUERY(A2:D17,"select B,C where A matches '"&F4&"' and D = 'T1'",0))
This should be closer to what I'm looking for but spits out a row mismatch error:
=QUERY({A:A,B:B&" - "&C:C&char(10),D:D},"select Col2 where Col1 matches '"&F4&"' and Col3 ='T1'",0)
And of course neither of these does this as an array and I'm trying to avoid having to maintain the sheet as sessions and speakers are added. I struggle with the intricacies of the query function so any help/instruction you can give would be very much appreciated!
Example Data
try:
=ARRAYFORMULA(TEXTJOIN(CHAR(10), 1, QUERY({A:A, B:B&" - "&C:C, D:D},
"select Col2
where Col1 matches '"&F4&"'
and Col3 ='T1'", 0)))

SSRS 2012 Set a chart series legend from another dataset based upon the column name

I'm back with a question about the feedback card application.
For my final chart, I have a stored procedure with a dynamically built pivot query that has columns named Col1, Col2, Col3, ... Col 30, CardDate and FormattedCardDate. The columns either have data for a specific card feedback type (up to 30), as selected on the report setup form.
I also have another dataset with the display titles for the selected feedback types with the following columns Feedback ID, DisplayTitle and ColName.
I have tried to use a lookup for the legend like:
=Lookup(Fields!Col1.UniqueName, Fields!ColName.Value, Fields!DisplayTitle.Value, "dsGetLabels")
With the following data:
ID DisplayTitle ColName
================================================
1 Room Cleaned Col1
4 Kitchenette Counter Col2
...
But it only dislpays Col1 for Col1, not "Room Cleaned" as in the column name dataset.
How do I make the lookup work? Barring that, how can I add the correct column names to my stored procedure, but still access the data?
As an aside, I can pass the correct column names to the SSRS Chart as a parameter, but how would I display them as a legend?
If your main dataset is returning only a few hundred or a few thousand rows then you should see no difference between adding four extra fields to your main dataset, however, your type dataset solution is just as valid and would be ideal for super huge datasets.

Select last measure date for each ID at the same work date

I have a table like the next one and I would like to obtain the last "measure date" for every "Work date" of a same "ID".
At the end I would like to have this result:
In that example, the last two rows of the initial table disappears in the final one because I just want the last "To do" measure entered in the table for every work date of a same ID.
As you see in the first table, for a same ID I can have 2 differents measure_date for a same work date. However I need only the last measure date a same work date by ID. In that case, I need to get the last measure date to get the good "To Do" to achieve my job .
The table can have a lot of different Work Date and 100 of ID, which are the same for every Work date.
How can I do that?
From what I read the query should go something like this,
SELECT id, work_date, max(measure_date), todo FROM tablename GROUP BY id, work_date;
But notice that the todo value will be quite random (or can have unexpected results) so leave it out from the query. But like with the comments, there is not enough information and it does look like excel.

How can I get SSRS to create subheadings?

The Problem
I'm building an SSRS report which requires regular group headings on certain rows. The data returned from the database query includes a column with a bit flag indicating which rows need to be treated as group subheadings.
Here's a snippet of the source data:
Note the IsGroupHeading column, where the flag is set to 1 on the first row ("0401").
I want to produce output which looks like this Excel mockup:
So every time the report encounters a row where IsGroupHeading equals 1, it generates a bold group heading row followed by a row with column headings.
What's Happening
I've tried creating a row group in SSRS with the expression =Fields!IsGroupHeading.Value = 1 but I get unexpected results: (1) Only the first group heading is treated specially, and (2) the group heading row is repeated underneath the heading. The result looks like this:
Notice that the "0401" row is repeated under the group heading. In addition, only the first group heading ever gets this special treatment. The report simply ignores subsequent group headings and renders them as normal data rows.
The Question
I've spent hours trying to get this right and this is the closest I've been able to get it and my googling on row groups turns up pages mostly about creating subtotals, so I'm throwing this one out to the community hoping some SSRS experts can help me with this.
I'm going to assume that you're doing this in SQL and that all tariff numbers start with the group header tariff number (in this case, 0401).
Let's say your SQL currently looks like this:
SELECT TariffNumber, RowDescription, TariffRate, IsGroupHeading
FROM Tariffs
What we want to do is join this table on itself to give the group TariffNumber and RowDescription columns on each row to enable us to group on it. We also want to exclude the GroupHeader Tariff from the Details rows. So we get something like this:
SELECT TariffGroup.TariffNumber AS GroupNumber, TariffGroup.RowDescription AS GroupDescription,
TariffDetail.TariffNumber, TariffDetail.RowDescription, TariffDetail.TariffRate
FROM Tariffs AS TariffDetail
INNER JOIN Tariffs AS TariffGroup ON TariffGroup.TariffNumber = Left(TariffDetail.TariffNumber, CharIndex(TariffDetail.TariffNumber, '.')-1) AND TariffDetail.IsGroupHeader = 0
Now you just need to group on GroupNumber and you're done.

Resources