0
"Id","Name","Salary","Location","Date"
123,"Ganesh",10000,"Pune","02/22/2020"
234,"Sanket",20000,"Mumbai","02/20/2021"
345,"Mohan",30000,"Kolkata","01/23/2023"
123,"Ganesh",30000,"Chennai","02/28/2023"
234,"Sanket",40000,"Goa","02/20/2024"

Above is my payload. I want to update Salary to 50000 where location = 'Mumbai' and Date > 01/20/2020.

Unable to achieve yet.

2
  • 1
    What did you try? Commented Aug 9, 2024 at 14:41
  • Yes, defininitely show us what you were thinking as you worked toward the answer. More valuable than the excellent answer @aled provided might be validation of your thinking. Maybe you were close and just needed one bit of understanding? Commented Aug 14, 2024 at 17:27

1 Answer 1

1

You can use the update operator to conditionally change each record. To compare the date first convert to an actual Date type. Comparing dates using string comparisons is a bad idea. Then map each record using the previously defined update.

%dw 2.0
output application/csv
---
payload map ((item) -> item update {
    case salary at .Salary if (item.Location == "Mumbai" and item.Date as Date {format:"MM/dd/yyyy"} > |2020-01-20|) -> 50000
})
Sign up to request clarification or add additional context in comments.

2 Comments

Excellent suggestion and a great us of the update operator. For consistency with the original dataset, perhaps the lambda for that update case could be: '50000 as String'
In the input CSV column Salary is numeric. Note that the values of Name or Location are between double quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.