Link to example file:
https://docs.google.com/spreadsheets/d/1dCQSHWjndejkyyw-chJkBjfHgzEGYoRdXmPTNKu7ykg/edit?usp=sharing
The tab "Source data" contains the data to be used in the query on the tab "Query output". The tab "Desired result" shows what I would like the end result to look like.
The goal I'm trying to achieve is to have the formula in cell A2 on the tab "Query output" to populate the data in all four of the columns, so that it looks exactly like the "Desired result" tab. I know I can get the same result simply by entering additional formulas in C2 and D2, but this is not the objective, I need the results to come specifically from the single formula in A2.
The information in the "Additional data 1" column should simply repeat the word "Test" for every row that contains data in the first two columns. The information in the "Additional data 2" column should simply repeat the data from cell 'Source data'!A1 for every row that contains data in the first two columns.
Please feel free to edit the example file as it only contains dummy data. If you like, you can copy the tab "Query output" to create your own working formula for illustrative purposes.
EDIT:
I'm thinking along the lines of creating an array that consists of the required data for the columns "Additional data 1" and "Additional data 2" and then combining that array with the array of the query result which provides the first two columns. I've been experimenting with this in various ways, but so far the only result I have achieved is an error on the first cell of the query results. I also have no idea yet how I could make sure that the second array contains an equal amount of rows to the query result.
You can add static data into query:
=QUERY('Source data'!A3:B,"SELECT A,B, 'Test', '" & 'Source data'!A1 &"' WHERE A IS NOT NULL LABEL A '', B '', 'Test' '', '" & 'Source data'!A1 &"' ''")
Many thanks to #basic for the provided assistance! The insights were a great help to solving my issue. That said, I have muddled along a bit, and I've come up with a slightly different solution which I find better suited as it gives true blank values instead of a column filled with spaces.
First of all, instead of querying directly on the source data, I built an array and queried on that. I used the two existing columns (A and B) from the source data and added a third column to the array which does not exist in the source data. In order to make sure that the third column would consist of blank values, I used the IFERROR formula.
=IFERROR(0/0)
The formula above returns a blank because dividing by zero forces an error and the IFERROR method returns a blank unless an alternative return value is specified.
In order to be able to use this formula in an array however, it had to be tweaked slightly, because as it is it would only return a single blank cell value instead of a column of blank values. To do this, I used an already existing column from the source data, and then encapsulated it in an ARRAYFORMULA.
=ARRAYFORMULA(IFERROR('Source data'!A3:A/0))
Using this, the resulting array has the following formula.
=ARRAYFORMULA({'Source data'!A3:A,'Source data'!B3:B,IFERROR('Source data'!A3:A/0)})
This creates an array consisting of the two original columns A and B from the source data, plus an additional third column filled with blank values. This array can now be queried upon, and using the tricks previously provided by #basic the desired result as specified in the original question can be achieved.
Due to the query now being used upon a user-defined array, the columns in the SELECT statement now have to be referred to as Col1, Col2, Col3, instead of A, B, C. The final formula now looks like this.
=QUERY(ARRAYFORMULA({'Source data'!A3:A,'Source data'!B3:B,IFERROR('Source data'!A3:A/0)}),"SELECT Col1,Col2,'Test',Col3,'"&'Source data'!A1&"' WHERE Col1 IS NOT NULL LABEL 'Test' '','"&'Source data'!A1&"' ''")
I hope this information may prove of use to someone else as well.
I made a query that only shows me a single field and a single record from another query, how can I put that value in a textbox in a report?
The record I want to set is a date that I insert with a MsgBox.
I read that there are ways to just put in the Control Source "=[table]![field]" but I get the Name? error, another way I read but did not understand it is defining a recordset. I can't put the value to the textbox despite trying the ways I've read in other posts.
One simple way is with DLookup() domain aggregate function expression in textbox. If field name has space or punctuation/special characters or is a reserved word, [ ] delimiters will be required. Usually table/query name does not but can't hurt.
=DLookup("[fieldname]","[tableORquery name]")
I have a stored procedure which drops either 1 or 2 columns from the result set. In my SSRS report, I have all possible columns that may come from the result set as dataset fields. I am trying to use the IsMissing function to change the column visibility, but it is not working. How can I make this functionality work?
I tried using examples from
https://sqlserverbi.blog/tag/hide-columns/
and
https://www.allaboutmssql.com/2013/01/ssrs-ismissing-visibility-function.html
where I right click the column, select Column Visibility and add an expression to the Show or hide based on an expression line.
Here is how I have been trying to use the expressions:
When I want to hide 2 of the columns I use:
=Fields!LINE_30_A.IsMissing And Fields!LINE_30_B.IsMissing
and when I want to hide only one of them I use:
=Fields!LINE_30.IsMissing
I have also tried the expressions like this:
=IIF(Fields!LINE_30_A.IsMissing And Fields!LINE_30_B.IsMissing,True,False)
I ran my stored procedure in a way that has dropped 1 of the columns from the result set. In this case the expression Fields!LINE_30.IsMissing should have been evaluated and I should be seeing the columns for Fields!LINE_30_A and Fields!LINE_30_B. But I only see the column for Fields!LINE_30 (which shouldn't be showing at all) and the other 2 columns are hidden. I also receive these 2 warnings:
1) Warning [rsErrorReadingDataSetField] The dataset ‘DataSet1’ contains a definition for the Field ‘LINE_30’. The data extension returned an error during reading the field. There is no data for the field at position 11.
2) Warning [rsMissingFieldInDataSet] The dataset ‘DataSet1’ contains a definition for the Field ‘LINE_30’. This field is missing from the returned result set from the data source.
I have some data that I want to be displayed the following way and I cannot find how to do it:
For example this would be the keep together case:
But I don't like that I have a lot of blank spaces when data is too much, so I would like the following to happen if possible.
When the colNames and the first row can fit in the remaining space put them there.
Or if more can fit after the first row, put all of them there and split where it is possible if necessary.
Basically I want a 'Keep together' option for the columns and first row, and everything else can be splitted at any point.
If anyone wants to achieve the same functionality do the following:
Put the table column names inside a GroupHeader and set its GroupUnion property to WithFirstDetail.
Put the table rows in the Detail next to the GroupHeader.
By doing this the WithFirstDetail property, as the name suggests, will try to keep the header with the first record, or move to the next page. Therefore achieving the behavior described above.
I've got a matrix that looks like this:
And I would like to hide the column with no data (i.e. second one for the date 21.05...).
I have tried applying expression "IsNothing" and '...Value = ""...' in Visibility field of the Column and of the Group.
How can i get it to hide the "empty" column?
Thank you in advance!
Write This Expression On Column Visibility Property Of Every Column.
=IIF(COUNT(Fields![ColumnName].Value) = Cint(0),TRUE,FALSE)