# Formula for calculating out of pocket expenses using insurance

Hi there!

I keep feeling like the way to do this is just within reach... and then I try and I still can't figure it out

What I want to have happen is to select one or more options from a dropdown (I've successfully made this part, at least! After this I'm stuck). Then, I'd like a numeric value (estimated cost of treatment) assigned to each option and plugged into a formula to calculate out of pocket cost using deductible, coinsurance, and maximum out of pocket values that are filled in according to the member's plan earlier in the snippet.

So if I've selected treatments "x" "y" and "z" from my dropdown, I want it to assign the approximate cost I will have put in to the selected treatments and plug it into a formula, using the first value occurring on the list to calculate out of pocket cost. So, "x" is assigned a value of \$2,000,"y" is assigned \$500, and "z" is assigned \$1500. I've put in a deductible of \$500, 10% coinsurance and \$2,000 maximum out of pocket. So assuming all are billed in the order selected on the list, the patient could expect to pay their \$500 deductible + 10% of the remaining \$1500 for x. for y they'd have met their deductible and would only be responsible for the 10% coinsurance, so \$50. Same for z - 10%, unless the out of pocket cost meets a maximum out of pocket amount that I entered earlier in the snippet - out of pocket cost is equal to maximum out of pocket, patient responsibility for anything else checked would be 0.

I hope that makes sense! If anyone can help me create the formula needed for that, I'd be so thankful!

Hi @alliedee - welcome to the forum and kudos on being so ambitious with your snippets!

I'm having a bit of a hard time envisioning the complete process, but it looks like the first step would be to use keyed lists. Here's how that would work.

Let's start by creating the keyed list, which would look like this:

`{treatmentlist=[ "treatment 1"=2000, "treatment 2"=1300, "treatment 3"=9000 ]}`

I'm going to add this in the snippet below.

{note: trim=right}
{treatmentlist=[
"treatment 1"=2000,
"treatment 2"=1300,
"treatment 3"=9000
]}

{endnote: trim=right}

If I insert the variable `treatmentlist`, it will give me the following:
{=treatmentlist}

Note how the list is in pairs. There are three pairs of items, and each pair consists of a "key" and a "value".

Now I can recall items from that list and use them in various ways.

{note: trim=right}
{treatmentlist=[
"treatment 1"=2000,
"treatment 2"=1300,
"treatment 3"=9000
]}

{endnote: trim=right}

Using the `keys()` function, I can extract the "key" for each item on the list.
{=keys(treatmentlist)}

Moreover, I can use those keys as values inside a dropdown menu, like this:

Since I gave the label "choice" to my formmenu command, now whatever I pick will be "stored" inside that variable.

So using the variable "choice" below gives me this:
{=choice} (note how it changes dynamically)

Next, I can use my choice from the menu to recall the corresponding "value" from the keyed list.

{=choice} costs \${=treatmentlist[choice]}

I think this would probably handle the first part of the process. If that's the case, we can move on to the next stage of the workflow. But let's make sure we've nailed this part first.

Let me know

P.S. You can read more about ordered lists and keyed lists here: