I have table like this:
+---------------------------------+
| Group1 |
+-------+--------+----------------+
| Item1 | Value1 | Compare |
+-------+--------+----------------+
| Item2 | Value2 | Compare |
+-------+--------+----------------+
| Item3 | Value3 | Do not compare |
+-------+--------+----------------+
| Group2 |
+-------+--------+----------------+
| Item1 | Value1 | Compare |
+-------+--------+----------------+
| Item2 | Value2 | Compare |
+-------+--------+----------------+
| Item3 | Value3 | Do not compare |
+-------+--------+----------------+
In a table like this i can have multiple groups with multiple items. I need to compare only items, where "Compare" is written. For example, i need to change the color of Value1 in Group2, if that value is grater thant Value1 in Group1. How can i do that? If there would be only one line to compare in each group, it would be easy, but i don't know what to do when there are multiple lines.
So you need to compare new groups with an old group that you know the name of? This query will give you any new group and compare any items named the same where they have been flagged to be compared with the original group, Group1, and give you the old and new values:
SELECT New.GroupName AS NewGroup, New.ItemName AS NewItem,
Old.Value AS OldValue, New.Value AS NewValue
FROM MyTable New
INNER JOIN MyTable Old ON
Old.GroupName = 'Group1' AND
Old.ItemName = New.ItemName
Old.CompareField = 'Compare' AND
New.CompareField = 'Compare'
Related
is there a way to re-order parent row group in SSRS? I need the group to show on the 3rd column instead of first.
Col1 | Col2 | Group1 | Col3| Col4|
A | AX | GroupA | 12 |13 |
B | BX | | 14 |3 |
C | CX | | 32 |65 |
D | DX | GroupB | 54 |62 |
E | EX | | 56 |63 |
F | FX | | 576 |64 |
You can't have a group column in the middle of none grouped columns normally but you can get close.
First create your table as normal with Col1-Col4, then add the parent group using Group1.
The table will look like this...
Next, insert a new column after Col2 and select Group1 from the drop down.
The design will look like this...
Select the new textbox that contains Group1 and then in the properties panel, set the HideDuplicates property to be the name of the row group (as displayed in the row group panel under the main designer). In the case the row group is also called Group1
Finally, delete the original group column (the left column) and choose "Delete columns only" if prompted.
The final output will look like this...
I have the following google-sheet:
| | A | B | C | D |
| 1| | Item1 | Item2 | Item3 |
| 2| Value1 | yes | no | no |
| 3| Value2 | no | no | yes |
| 4| Value3 | no | yes | no |
I need to import specific data from this sheet into another range so result should contain values from A, which have "yes" between B:E, and related item from the first row, like:
Value1 Item1
Value2 Item3
Value3 Item2
I can import using query and condition for "yes", but no ideas how to read related cell with Item1, Item2.. from first row above:
=query({importrange("my_range_id", "Data!A1:Z999"}, "select Col1 where Col2='yes' or Col3='yes' or Col4='yes'")
Thanks for help in advance!
May be you can first import data, then retrieve the column corresponding to 'yes' by this formula using matrix multiplication
={A2:A5,arrayformula(mmult((if(B2:D5="yes",1,0)),transpose(column(B1:D1)-1)))}
and then retrieve the header of the column
=offset($A$1,,G2)
As an addition, in case you still want to use a query:
Try this in F2:
=ARRAYFORMULA(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(A2:A<>"",
"♦"&A2:A&"😊"&B1:D1&"😊"&B2:D, ))
,,999^99)),,999^99), "♦")), "😊"),"Select Col1,Col2 where Col3 contains 'YES'"))
Here is an integrated formula
={A2:A,arrayformula(vlookup(mmult((if($B$2:$D="yes",1,0)),transpose(column($B$1:$D$1)-1)),{arrayformula(transpose(COLUMN(A1:D1)-1)),transpose(A1:D1)},2,0))}
I have a large table with person info. Every record has an ID and is referenced by other tables. I noticed that a lot of records have duplicate keys, but they vary in the amount of information in the other fields. I'd like to merge the info in various fields into one and make that the 'master' record and all references to the other records need to be replaced with the master record.
An example
| id | key1 | key2 | name | city | dob |
|--- | ---- | ---- | ---- | ---- | -------- |
| 1 | 1 | 2 | John | | |
| 2 | 1 | 2 | | Town | |
| 3 | 1 | 2 | John | | 70/09/12 |
I need to end up with a single record (id is either 1, 2 or 3) with values
key1 = 1, key2 = 2, name = John, city = Town, dob = 70/09/12.
Is there a clever way to merge these records without testing for every field (my actual table has a lot of fields)?
You can use MAX() to get the non-empty values for each key.
SELECT key1, key2, MAX(id) AS id, MAX(name) AS name, MAX(city) AS city, MAX(dob) AS dob
FROM yourTable
GROUP BY key1, key2
If there can be different values between rows, and you don't want to include them, you can add:
HAVING COUNT(DISTINCT NULLIF(name, ''), NULLIF(city, ''), NULLIF(dob, '')) = 1
I'm curious if there is an easy way to archive this query:
SomeTable.where(value_b: SomeTable.where(value_a: 1).pluck(:value_b))
For an example, if we have:
SomeTable
|id | a | b |
|1 | 1 | 2 |
|2 | 2 | 2 |
|3 | 3 | 3 |
|4 | 4 | 4 |
And the user enter number 1 into the system, I want to be able to find value of b where value of a = 1, which is 2. Then use this value of b to find all the records with this value.
So, I want to be able to use 1 and extract SomeTable with id: 1 and 2
Thanks!
SomeTable.joins("JOIN some_table as replica on replica.value_b = some_table.value_b")
.where(replica: {value_a: 1})
SomeTable.where("b in (SELECT b FROM some_tables where a = ?)", a_value)
a_value is your 'a' value to find 'b' value
I have a table with 2 Columns, filled with strings
CREATE TABLE [tbl_text]
(
[directoryName] nvarchar(200),
[text1] nvarchar(200),
[text2] nvarchar(200)
)
The Strings are build like the following
| Text1 | Text2 |
|------------|----------|
|tz1 tz3 tz2 | al1 al2 |
| tz1 tz3 | al1 al3 |
| tz2 | al3 |
| tz3 tz2 | al1 al2 |
Now i want to Count how many times the TestN or TextN are resulting in the
| Text1 | al1 | al2 | al3 |
|-------|------|------|------|
| tz1 | 2 | 1 | 1 |
| tz2 | 2 | 2 | 1 |
| tz3 | 3 | 2 | 1 |
i tried solving it with an sql-query like this:
TRANSFORM Count(tt.directoryName) AS Value
SELECT tt.Text1
FROM tbl_text as tt
GROUP BY tt.Text1
PIVOT tt.Text2;
This works fine if i got fields only with one value like the third column (the complete datasource has to be like a one-value-style)
But in my case i'm using the strings for a multiselect...
If i try to conform this query onto a datasource filled with the " " between the values the result is complete messed up
Any suggestions how the query should look like to get this result ?
You'll have to split the strings inside Text1/Text2 before you can do anything with them. In VBA, you'd loop a recordset, use the Split() function and insert the results into a temp table.
In Sql Server there are more powerful options available.
Coming from here: Split function equivalent in T-SQL? ,
you should read this page:
http://www.sommarskog.se/arrays-in-sql-2005.html#tablelists