In CM I have a Column “Customer No.” and it has a 6 character Alpha-Numeric value.
In FCCM, I have a column name “Internal Account” and has a alpha-numeric value of length 13.
The above assignment will store 6 character in row(“Internal Account”).
Then I took “Lookup Data Table” and want to count the number of occurrences of 6 characters in the CM “Customer No.” field. This CM field has also 6 characters value and want to lookup in row(“Internal Account”).
Inside For each row,
Assign a variable InternalAccount = row(“Internal Account”).ToString.Substring(5,10)
Use Filter data table activity, input dtCM variable and create dtRequired variable. Provide the condition as Column Name “Customer No.” = InternalAccount variable
@Robinnavinraj_S : When I use the assign activity outside the for each loop, it gives me an error that “Customer No.” does not belong to the data table.
@supermanPunch : Yes, indeed, you are right. I have also given the screenshot for the issue and two to three community members also replied me. I am preparing the sample excel files to further understand my problem.
@supermanPunch : Pl. find attached the two excel files Book1 and Book2. Actually I want to vlookup the value from Book1 to Book2. If matches so count the occurrences of Book1 value in Book2 Value. Book2 value has the column which has to be extracted through substring function then match the corresponding value in Book1.
It is the same working as in excel with CountIF formula.
Let’s say the Primary Steps of reading the file are already known and are done.
So Book1.xlsx and Book2.xlsx are read using Read Range Activity and assigned Datatable variables. Let the variables be DT1 and DT2.
Now, we can use an Assign Activity to Clone the DT1 as it is similar to Output required as shown in below image. OutputDT is also a variable of Type Datatable
Next Use Add data column Activity to Add "Book2 Count" Column to OutputDT
Now, we can Loop through the DT1 datatable value and Count the number of occurrences of values in the DT2 datatable.
Use For Each Row Activity with DT1 as the Input
Inside For Each Row, Use an Assign Activity to Calculate the Number of Occurrences using a Linq Expression as below
The Screenshot of the Assign is shown below , where count is a variable of Type Integer
Next use Add Data Row Activity to add the Customer No. and It’s Number of Occurrences Stored in count variable to OutputDT as shown in the image below:
The For Each Activity Should look like the Below Image :
Outside the For Each Loop, Use WorkBook Write Range Activity, and use the OutputDT as the datatable variable like below.
This Sequence of Steps should help you achieve the Required Output. Let us know if you Still face issues.
Thanks a lot @supermanPunch for your hats off effort but pl. find below the screenshot, I actually want to insert the Lookup Data Table instead of Add Data Row. But in the Lookup Column under the Column Name, which lookup column name should I mention? Thanks,
According to the Output file that you have Provided, you would have to generate a Table / Datatable which includes the Customer No.'s with it’s Corresponding Number of Occurrences.
I do not see why the LookUp datatable is Required.
@supermanPunch : Yes, indeed, I want to add a new column in the existing sheet of excel file and then past the count of occurrences of “Customer No.” after matching through another excel file which you have shared me the LINQ code. In fact, I want to add a new column in Book1.xlsx not in the Output.xlsx. I have just shared Output.xlsx as a sample that shows the required output. So, this output I want to incorporate in Book1.xlsx.
In that case, We can just Change the Output File in Write Range Activity. You can change the filepath to the Book1.xlsx path and also the Sheetname to the Sheet1 as it is present in the file.