Multiple Values To A column

Hi All,

I have a Column In Excel Sheet where there are already two values separated by comma . I want to add the third value to the same column based on conditions:


I want to check if
CurrentRow(“QuoteNumber”).ToString of Output Sheet is equal to CurrentRow(“QuoteNumber”).To String of Unmatched Sheet AND CurrentRow(“GeneralClause_Field”).ToString =“General Clause Is not Matched”

Insert, General Clause is Not Matched in Sheet Name=Unmatched in Column(Mismatched Data)

My Output should be like. It should not replace previous values but add just by comma to the already present value

@Anil_G Any suggestions from your side

First you need to get existing value, the you use add the new value and write into the same place

// this need to be get from file 
Var_existing_value = "A,B,C"
Var_new_value = "D"

// Add new value 
Var_WriteVlaue = Var_existing_value +", "+Var_new_value 

Write un same location

@dutta.marina I just provided to you logic and you can build according to your logic.

@dutta.marina

Use like this

CurrentRow("GeneralClause_Field") = (CurrentRow("GeneralClause_Field").ToString + ",General Clause Is not Matched").Trim.TrimStart(","c)

Cheers

@Anil_G

These are in two different sheets,. If the currentRow(“GeneralClauseFields”) contains value “General Clause Is n0t matched”, then it should update in other sheet column(“MismatchedData”) as (keeping previous values plus appending new value with comma)

Something like for Q30564 MismatchedData =PaymentTerms, TotalContractValue,PrimaryContact , GeneralClause Is not Mismatched.

Here the primary Key is QuoteNumber between two sheets.

@dutta.marina

Try this in invoke code…send dt1 and in/out and dt2 as in

dt1.AsEnumerable.ToList.ForEach(Sub(r) r("MisMatchedData") = r("MisMatchedData").ToString + "," + If(dt2.AsEnumerable.Any(function(x) x("QuoteNumber").ToString.Equals(r("QuoteNumber").ToString)), dt2.AsEnumerable.Where(function(x) x("QuoteNumber").ToString.Equals(r("QuoteNumber").ToString))(0)("GeneralClause_Field").ToString,"").Trim(","c))

Cheers

1 Like

@Anil_G

How to resolve this compile code errors.

@dutta.marina

Some bracket or something is missing…please show fullcode

Cheers

@Anil_G

(dt1.AsEnumerable.ToList.ForEach(Sub(r) r(“MisMatchedData”) = r(“MisMatchedData”).ToString + “,” + If(dt2.AsEnumerable.Any(Function(x) x(“QuoteNumber”).ToString.Equals(r(“QuoteNumber”).ToString)), dt2.AsEnumerable.Where(Function(x) x(“QuoteNumber”).ToString.Equals(r(“QuoteNumber”).ToString))(0)(“GeneralClause_Field”).ToString,“”).Trim(","c))

I have used this

@dutta.marina

Please remove the bracket at the start

Cheers

@Anil_G

No compilation errors but it didnot update the GeneralClause_Field
field is not mismatched under column(“Mismatched Data”) for Q30564. Do I need to write to excel after this code?

@dutta.marina

First we are updating mismatcheddata column with general clause and yes we need to write to excel after this

Cheers

@Anil_G

Directly I need to use the invoke code and write to Excel or need to put some If condition and invoke code.

@dutta.marina

you dont need a loop as that is taken care in invoke code…so this will apply for all rows

cheers

@Anil_G

Your code works perfectly. Thank You so much.

Can you please explain what you did in this code. It looking very complex

1 Like

@dutta.marina

Looping through DT1
dt1.AsEnumerable.ToList.ForEach

Updating Mismatcheddata with mismatcheddata and new data
(Sub(r) r(“MisMatchedData”) = r(“MisMatchedData”).ToString + “,” +

Validation if dt1 current row r is matching with any rows
If(dt2.AsEnumerable.Any(function(x) x(“QuoteNumber”).ToString.Equals(r(“QuoteNumber”).ToString)),

If matched get the dt2 matched row and get the generalclausefield
dt2.AsEnumerable.Where(function(x) x(“QuoteNumber”).ToString.Equals(r(“QuoteNumber”).ToString))(0)(“GeneralClause_Field”).ToString,

Else send empty
“”).

At last trim if there is any comma at start and end
Trim(","c))

Hope this helps

cheers

1 Like

@Anil_G

Can one more condition be added . Get the General Clause field only when the value of that field is "General Clause Is not matched " else do not updated in MisMatchedData fields.

x(“GeneralClause_Field”).ToString=“General Clause Is not Matched”

Here its updating GeneralClause is Matched and General Clause Is not Matched. If I just want to update “GeneralClause Is not Matched "
dt1.AsEnumerable.ToList.ForEach(Sub(r) r(“MisMatchedData”) = r(“MisMatchedData”).ToString + “,” + If(dt2.AsEnumerable.Any(function(x) x(“QuoteNumber”).ToString.Equals(r(“QuoteNumber”).ToString) AND Any (function(x)x(“GeneralClause_Field”).ToString=“General Clause Is not Matched”)),dt2.AsEnumerable.Where(function(x) x(“QuoteNumber”).ToString.Equals(r(“QuoteNumber”).ToString))(0)(“GeneralClause_Field”).ToString,”“).Trim(”,"c))

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.