Pass a table as variable - Pentaho - pentaho

I have a url: https://api.xero.com/api.xro/2.0/Reports/ProfitAndLoss?fromDate=2019-06-01&toDate=2019-06-30 which I will use after to call Xero's API.. I need to change fromDate and toDate dynamically. I thought to use https://api.xero.com/api.xro/2.0/Reports/ProfitAndLoss?fromDate=${start}&toDate=${end}. Then, add 'Data grid' with dates to be replaced in the string. But then, I tried to 'Set variables'/'Get variables' but I keep on getting the error 'Only 1 input row was expected to set the variables and at least 2 were received.' What am I doing wrong?
Current transformation:
Transformation:
Sub-job:
Final transformation:

In the set variable you can only set one row. but if you want to pass multiple rows then I suggest you to use job. In job first transformation use Data Grid and then copy rows to result. then create one more sub job. For setting variable use transformation. Make sure execute at every input row is checked. this should be your subjob Structure

Related

Excel VBA - Creating a Table In a Specific Non-Default(A1) Location

If you run the following code:
WorkSheet.ListObjects.add(SourceType:=xlSrcRange, Destination:=Range("A10:C13"))
One might be tempted into thinking, this would place table in the range of "A10:C13". It does not, a table is instead inserted into A1 with one column and one row(excluding the header):
This is clearly specified in the Official Documentation of this function:
The Destination argument is ignored if SourceType is set to
xlSrcRange.
How do you insert a table into any other range of cells?
You are adding your worksheet range definition into the wrong parameter.
WorkSheet.ListObjects.add SourceType:=xlSrcRange, Source:=WorkSheet.Range("A10:C13")
See ListObjects.Add Method (Excel) for a full description of the method.
Using the documentation provided from this page, I simulated what a user might do to add a table:
Range("A10:C13").Select
WorkSheet.ListObjects.add(SourceType:=xlSrcRange)
It seems adding the select statement will place the table into the correct location.

Using OBIEE Presentation Variables in Column Formula

I have a dashboard prompt setting a presentation variable, based on months.
I am then trying to use the presentation variable in column formulae, however I am getting the following error when I try to preview it by selecting the month of February:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27005] Unresolved column: "February". (HY000)
COlumn Formula :
FILTER("Fact WayLeave Movements"."WayLeave Movement" USING ("Dim Date"."Month Name" IN (#{MonthName}{'January'})))
However when I use the same variable in the analysis filter (not in the column formula, but whole analysis) it seems to run fine. But I need the presentation variable applied on particular columns and not on all of them.
Could anyone please advise how to achieve this or what I am doing wrong when using the presentation variable in the column formula.v
--Create a prompt with sql query which will fetch all month name or month number
--Assign a presentation variable to that prompt
--use that variable as a filter condition in analysis for that particular column.
So how it works is--when u select any month name from prompt that will be assigned to variable.And same month name in that variable will be used as filter condition for your column and and it will fetch data accordingly and report will run properly.
PFB a blog related to presentation Variable.
"https://blogs.oracle.com/ExalyticsOBIEE/entry/how_to_pass_presentation_variable
I assume you have setup a presentation variable already called MonthName, yo will need to add the formulae like this (#{MonthName}['#']{'January'}). in between mothname and default January.
Hope that helps.

SSIS Result set, Foreachloop and Variable

I'm having an issue and I don't know if this is possible to do.
I have a simple SQL task.
SELECT Name, email FROM table_name
Using a result set, I'm trying to pass it to a variable and use it on a email task with a foreach loop but i having no luck getting this to work. If I do just one column, it works fine. My issue is multiple columns.
Thanks for the help in advance.
I figured out my own question. I will add it here in case someone else have the same issue.
On the SQL query the first column should be your key result. for example mine was the email.
In the SQL Task under General, set Resultset to "Full Result rest"
In the SQL Task under Result Set, set variable with "0" as result name, create a variable as "Object" data type for the email column and click ok to save and exit. Example: email_Ob
By going to the variable window, create more variable for the other columns as Object and since I'm using this for email task I need to convert from Object to String, so I need to create another variable as string for each one
Example:
**Variable Name** **Datatype**
email_Ob Object
Name_Ob Object
email_St String
Name_St String
Foreach Loop task Under Collection change the following:
Enumerator: Foreach ADO Enomator
ADO object Source variable: Select the key variable (email_Ob)
Select Rows in the first table
Foreach Loop task under Variable Mappings add the variable with String data type the same order as on your SQL query. Click OK to save and exit.
Now you can add the Email Task inside Foreach Loop and use those String variable as part of the email or you can use it for any other task.
Hope this help and if you have any questions feel free to ask. Doing this way, I was able to add more columns as need it.

Column references in formulas

I am a little stuck at the moment. I am working on an array of data and need to find a way to input column numbers into formulas.
-I have used the match function to find the corresponding column number for a value.
ex. "XYZ" matched with Column 3, which is equivalent to C1:Cxxxxxx
-now for inputing the C1:Cxxxxxx into a formula to get data for that particular column, I would like to be able to directly reference the Column 3 part, because I plan on using this workbook in the future and the column needed to run the calculation may or may not be column 3 the next time I use it.
- is there any way to tell excel to use a formula to tell excel which column to use for an equation?
so a little more detail, I have the equation
=AND(Sheet3!$C$1:$C$250000=$A$4,Sheet3!$B$1:$B$250000=$B$4)
instead of specifying to use column C, is there a way to use a formula to tell it to use C?
EDIT: more additional info;
"i am basically running the equivalent of a SQL where statement where foo and bar are true, I want excel to spit out a concatenated list of all baz values where foo and bar are true. ideally i would like it to ONLY return baz values that are true, then I will concat them together separately. the way I got it now, the expression will test every row separately to see if true; if there is 18K rows, there will be 18K separate tests.. it works, but it's not too clean. the goal is to have as much automated as possible. *i do not want to have to go in and change the column references every time I add a new data arra*y"
Thanks
You can use INDEX, e.g. if you have 26 possible columns from A to Z then this formula will give you your column C range (which you can use in another formula)
=INDEX(Sheet3!$A$1:$Z$250000,0,3)
The 0 indicates that you want the whole column, the 3 indicates which column. If you want the 3 can be generated by another formula like a MATCH function
Note: be careful with AND in
=AND(Sheet3!$C$1:$C$250000=$A$4,Sheet3!$B$1:$B$250000=$B$4)
AND only returns a single result not an array, if you want an array you might need to use * like this
=(Sheet3!$C$1:$C$250000=$A$4)*(Sheet3!$B$1:$B$250000=$B$4)
You could use ADDRESS to generate the text, you then need to use INDIRECT as you are passing a string rather than a range to the fomula
=AND(INDIRECT(ADDRESS(1,3,,,"Sheet3") & ":" & ADDRESS(250000,3))=$A$4
,INDIRECT(ADDRESS(1,2,,,"Sheet3") & ":" & ADDRESS(250000,2))=$B$4)
Obviously replace the 3s and 2s in the ADDRESS formulae with your MATCH function you used to get the column number. The above assumes the column for $B$1:$B$25000 is also found using `MATCH', otherwise it is just:
=AND(INDIRECT(ADDRESS(1,3,,,"Sheet3") & ":" & ADDRESS(250000,3))=$A$4
,Sheet3!$B$1:$B$25000=$B$4)
Note a couple of things:
You only need to use "Sheet3" on the first part of the INDRECT
Conditions 3 and 4 in the ADDRESS formula are left as default, this
means they return absolute ($C$1) reference and are A1 style as
opposed to R1C1
EDIT
Given the additional info maybe using an advanced filter would get you near to what you want. Good tutorial here. Set it up according to the tutorial to familiarise yourself with it and then you can use some basic code to set it up automatically when you drop in a new dataset:
Paste in the dataset and then use VBA to get the range the dataset uses then apply the filter with something like:
Range("A6:F480").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Sheet1").Range("A1:B3"), Unique:=False
You can also copy the results into a new table, though this has to be in the same sheet as the original data. My suggestion would be paste you data into hidden columns to the left and put space for your criteria in rows 1:5 of the visible columns and then have a button that gets the used range for your data, applies the filter and copies the data below the criteria:
Range("A6:F480").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets _
Range("H1:M3"), CopyToRange:=Range("H6"), Unique:=False
Button would need to clear the destination cells first etc, make sure you have enough hidden columns etc but it's all possible. Hope this helps.

SSIS custom script: loop over columns to concatenate values

I'm trying to create a custom script in SSIS 2008 that will loop over the selected input columns and concatenate them so they can be used to create a SHA1 hash. I'm aware of the available custom components but I'm not able to install them on our system at work.
Whilst the example posed here appears to work fine http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/69766/ when I've tested this selected only a few and not all columns I get odd results. The script only seems to work if columns selected are in sequential order. Even when they are in order, after so many records or perhaps the next buffer different MD5 hashes are generated despite the rows being exactly the same throughout my test data.
I've tried to adapt the code from the previous link along with these articles but have had no joy thus far.
http://msdn.microsoft.com/en-us/library/ms136020.aspx
http://agilebi.com/jwelch/2007/06/03/xml-transformations-part-2/
As a starting point this works fine to display the column names that I have selected to be used as inputs
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
For Each inputColumn As IDTSInputColumn100 In Me.ComponentMetaData.InputCollection(0).InputColumnCollection
MsgBox(inputColumn.Name)
Next
End Sub
Building on this I try to get the values using the code below:
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Dim column As IDTSInputColumn100
Dim rowType As Type = Row.GetType()
Dim columnValue As PropertyInfo
Dim testString As String = ""
For Each column In Me.ComponentMetaData.InputCollection(0).InputColumnCollection
columnValue = rowType.GetProperty(column.Name)
testString += columnValue.GetValue(Row, Nothing).ToString()
Next
MsgBox(testString)
End Sub
Unfortunately this does not work and I receive the following error:
I'm sure what I am trying to do is easily achievable though my limited knowledge of VB.net and in particular VB.net in SSIS, I'm struggling. I could define the column names individually as shown here http://timlaqua.com/2012/02/slowly-changing-dimensions-with-md5-hashes-in-ssis/ though I'd like to try out a dynamic method.
Your problem is trying to run ToString() on a NULL value from your database.
Try Convert.ToString(columnValue) instead, it just returns an empty string.
The input columns are not guaranteed to be in the same order each time. So you'll end up getting a different hash any time the metadata in the dataflow changes. I went through the same pain when writing exactly the same script.
Every answer on the net I've found states to build a custom component to be able to do this. No need. I relied on SSIS to generate the indexes to column names when it builds the base classes each time the script component is opened. The caveat is that any time the metadata of the data flow changes, the indexes may change and need to be updated by re-opening and closing the SSIS script component.
You will need to override ProcessInput() to get store a reference to PipelineBuffer, which isn't exposed in ProcessInputRow, where you actually need to use it to access the columns by their index rather than by name.
The list of names and associated indexes are stored in ComponentMetaData.InputCollection[0].InputColumnCollection, which needs to be iterated over and sorted to guarantee same HASH every time.
PS. I posted the answer last year but it vanished, probably because it was in C# rather than VB (kind of irrelevant in SSIS). You can find the code with all ugly details here https://gist.github.com/danieljarolim/e89ff5b41b12383c60c7#file-ssis_sha1-cs