I'm trying to write code that will automatically filter a column based on certain criteria no matter where that column occurs in the sheet.
I started by creating a named range and referencing that named range. However, I am trying to figure out how I can reference the column number based on the name range as this will vary based on where the column is in the sheet. Particularly, I am trying to fix the arguments within setColumnFilterCriteria which requires the column number.
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('AttendeeStatus').activate();
spreadsheet.getRange('AttendeeStatus').createFilter();
spreadsheet.getRange('AttendeeStatus').activate();
var criteria = SpreadsheetApp.newFilterCriteria()
.setHiddenValues(['', 'Attending'])
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(, criteria);
Currently, this requires me to manually enter the right column - is there anyway to automate this?
try this, it may work.
var columnNo = spreadsheet.getRange('AttendeeStatus').getColumn();
Related
I have an excel sheet with many tabs. Say one is called wsMain and the other is called wsDate.
In my data flow transformation I am able to successfully load the data from wsMain to my table.
Now I have to update this transformation where I have to fetch the maximum date from the worksheet wsDate and only load data from wsMain where the date is less than on equal to the maximum date in wsDate (that is the only column available).
So for I have figured out that I need to create a new Excel connection manager to read the data from wsDate and I have used the Aggregate transformatioin to get the maximum date.
Now the question is how do I use this date to restrict the rows coming from wsMain?
I understand from the link below that you can store the value in a variable but what do I do next?:
SSIS set result set from data flow to variable
I have tried using a merge join but not sure if I am doing it right.
Here is what it looks like now:
I could not achieve the above but would be interested to know if that is possible. As a work around I have created a separate dataflow where I have stored the valued in a variable and then used the variable in the conditional split to filter the required rows:
Here is a step by step guide I followed to write the variable:
https://www.proteanit.com/2008/12/11/ssis-writing-to-a-package-variable-in-a-dataflow/
You can obtain the maximum value of the wsDate column first, this use this as a filter to avoid introducing unnecessary records into the data flow which which would be discarded by the Conditional Split. An overview of this process is below. I'd also recommend confirming the data types for all columns involved.
Create an SSIS DateTime variable and name this something descriptive such as MaxDate.
Create a Data Flow Task before the current one with an Excel Source component. Use the SQL command option for the Data Access Mode and enter a SQL statement to return the max value of the wsDate column. In the following example ExcelSource is the name of the sheet that you're pulling from. I'd suggested confirming the query with the Preview button on the Excel Source as well.
Add a Script Component (not Task) after the Excel Source. Add the MaxDate variable in the ReadWriteVariables field on the main page of the Script Component. On the Inputs and Outputs pane add the output column from the Excel Source as an Input Column with the ReadOnly usage Type. Example C# code for this is below. Note that variables can only be written to in the PostExecute method. The Input0_ProcessInputRow method is called once for each row that passes through, however there will only be the single row in this case. On the following code MaxExcelDate is the name of the output column from the Excel Source.
On the Excel Source component in the Data Flow Task where the records are imported from Excel, change the Data Access Mode to SQL command and enter a SQL statement to return records that have a date less than or equal to the maximum wsDate value. This is the last example and the ? is a placeholder for the parameter. After entering this SQL, click the Parameters button and select Parameter0 for the Parameters field, the MaxDate variable for Variables field, and a direction of Input. The Conditional Split can then be removed since these records will now be filtered out.
Excel MAX wsDate SELECT:
SELECT MAX(wsDate) AS MaxExcelDate FROM ExcelSource
C# Script Component:
DateTime maxDate;
public override void PostExecute()
{
base.PostExecute();
Variables.MaxDate = maxDate;
}
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
maxDate = Row.MaxExcelDate;
}
Excel Command with Date Filter:
SELECT
Column1,
Column2,
Column3
FROM ExcelSheet
WHERE DateColumn <= ?
Yes, it is possible. In the data flow, you will need to determine the max date, which you already have. Next, you will need to MERGE JOIN the two data flows on the date column. From there, you will feed it into a CONDITIONAL SPLIT and split where the date columns match [i.e., !ISNULL()] versus do not match [i.e., ISNULL()]. In your case, you only want the matches. The non-matches will be disregarded.
Note: if you use an INNER JOIN on the MERGE JOIN where there is only one date (i.e., MaxDate) to join on, then this will take care of the row filtering for you. You will not need a CONDITIONAL SPLIT.
Welcome to ETL.
Update
It is a real pain that SSIS's MERGE JOINs only perform joins on EQUAL operations as opposed to LESS THAN and GREATER THAN operations. You will need to separate the data flows.
Use a script component to scan the excel file for the MAX Date and assign that value to a package variable in SSIS. Alternatively, you can have a dates table in SQL Server and then use an Execute SQL Command in SSIS to retrieve the MAX Date from the table and assign that value to a package variable
Modify your existing data flow to remove the reading of the Excel date file completely. Then add a DERIVED COLUMN transformation and add a new column that is mapped to the package variable in SSIS that stores the MAX date. You can name the Derived Column Name 'MaxDate'
Add a conditional split transformation with the following CONDITION logic: [AsOfDt] <= [MaxDate]
Set the Output Name to Insert Records
Note: The CONDITIONAL SPLIT creates a new output data flow with restricted/filtered rows. It does not create a new column within the existing data flow. Think of this as a transposition of data flow output from column modification to row modification. Only those rows that match the condition will be sent to the output that you desire. I assume you only want to Insert these records, so I named it that. You can choose whatever naming convention you prefer
Note 2: Sorry for not making the Update my original answer - I haven't used the AGGREGATE transformation before so I was not aware that it restricts row output as opposed to reading a value in the data flow and then assigning it to a variable. That would be a terrific transformation for Microsoft to add to SSIS. It appears that the ROWCOUNT and SCRIPT COMPONENT transformations are the only ones that have the ability to set a package variable value within the data flow.
Please See Picture of my Tableau Worksheet
I simply want to include a new column that shows the difference between 2017SU and 2016SU. Note that each of those two columns are a running sum.
I've tried doing a secondary table calculation but it does not add a new column.
Here is one solution - more work than you would think it should take, but it makes sense when you think about Tableau views your data. I can't see what the full name of you numeric field starting with Seatc ...
Define three calculated fields:
2016SU Seatc = running_sum(sum(if [Stc Term] = "2016SU" then [Seatc...] end))
2017SU Seatc = running_sum(sum(if [Stc Term] = "2017SU" then [Seatc...] end))
diff = [2017SU Seatc] - [2016SU Seatc]
You'll have to set the partitioning and addressing (aka compute using) on the table calcs appropriately.
Finally, now you can use Measure Names and Measure Values to build a table (or other chart) using these 3 measures
I have two worksheets, each with the same variable but with different filters working on that variable in each worksheet.
For example:
In worksheet 1: [Run/100] = 2.1
In worksheet 2, with filters applied: [Run/100] = 4.0
What I would like to do is create a calculated field that takes the current value of [Run/100] in worksheet 1 and divides it by the current value of [Run/100] in worksheet 2. I have searched around, but can't seem to find anything on referencing worksheet values in Tableau.
Does anyone know of a way to do this?
I have 2 datasets in my report. And I need to put a number of rows that meet a certain condition in a text box.
Here's what I have so far:
=Sum(IIF((Fields!OPEN_TIME.Value, "calls")=Parameters!Date.Value,1,0))
I get following error while running the report:
The Value expression for the text bix uses an aggregate expression without a scope. A scope is required for all aggregate used outside of a data region unless the report contains exactly one dataset
What do I miss?
Here if you are specifying a dataset name to a field like this "(Fields!OPEN_TIME.Value,"calls")" its a syntax error.. if you are using the field in a table which is assigned to dataset1 and table is assigned to dataset2 or field in a text box, then the field should be used with aggregate or "First", "Last"
Example:
first(Fields!OPEN_TIME.Value, "calls")
last(Fields!OPEN_TIME.Value, "calls")
sum(Fields!OPEN_TIME.Value, "calls")
Count(Fields!OPEN_TIME.Value, "calls") ...etc
In above scenario rather than taking a textbox, take a table with single cell assign the dataset "calls" to it then go for below expression:
=Sum(IIf(Fields!OPEN_TIME.Value = Parameters!Date.Value, 1,0))
I have a SSRS matrix table, which generates column dynamically. but i want to add some static coloumn in that report(added manually). but the static columns will have the same value as one of the dynamic column. All i want to do is, find the specific dynamic column (a column name with DynamicColoumn1) and show it in this static column
=IIF(Fields!DynamicColumnData.Value = "DynamicColoumn1",Fields!DynamicColumnDataValue.Value, "")
this works only for the first data in the DynamicColumnData, not working for other values in the DynamicColumnData. Anyone faced similar problem?
Try changing your formula to use the First dataset field only:
=IIF(First(Fields!DynamicColumnData.Value, "DataSet1") = "DynamicColoumn1",First(Fields!DynamicColumnDataValue.Value, "DataSet1"), "")
I did this way
=Sum(IIF(Fields!DynamicColumnData.Value = "DynamicColoumn1",
Fields!DynamicColumnDataValue.Value, 0))
Not sure this is the efficient way of doing, but worked for me.