Need help in calculating field basis grid
-
There are 3 sheets in attached file.
Grid
Data
Output
We need to calculate fees on amount basis the grid provided. Refer the output sheet for desired outcome.
The only submission here is the grid may change for Fees or additional brackets ... and code should not be hard coded. It should do calculation basis the grid.
Attached files
-
I made an attempt at solving this using Json and the eval() function. The first step is to create Json. The Json key contains a single line Python if statement that will evaluate to true or false if the variable "val" is within the range. In the event of being it true, the fee amount to be charged is contained in the Json value.
After the Json has been constructed, we then bring it in as a field in the main dataset and then proceed to execute each of the Json keys (as they are actually Python statements) using eval(). When we get a true result, we can extract the fee amount from the Json value. The code is relatively simple, you just need some understanding of Json and eval().
You can read more about eval() here.
Attached files
Please sign in to leave a comment.
Comments
5 comments