• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Which formula to use????

niting

New Member
Hi forum,


Have a sheet with employee number mentioned in col a, col b mentions the serial number of dependants of employee number mentioned in COl A( if employee no. 1 has 4 dependants, den cell A2 to A5 would be blanks and cell B2 to B5 contains the serial number of dependants). Col C mentions the dependant relation with the employee like wife, son, daughter and Col D contains the insurance premium against the employee and dependants.


The cost the company would bear is for employee, wife, son and daughter.The recovery will be made from an employee if the relation is mother or father and if more 1 son/daughter is there.


How do I go about determining if the son/daughter against an employee is more than 1 and consequently determining the recovery to be made.


Thanks in advance

NitinG
 
There are several solutions, and your problem is a bit advanced. Without modifying the structure of your data a little, the formulas to solve your problem I think will be pretty slow.


So, I recommend some structural changes to your data.

Two alternatives come to mind:

(1) Normalize your data by splitting it into two table. One table has employee records, the other has just dependents (with the related employee# for each)


If that doesn't suit your needs, how about the milder:

(2) Include the employee# on every row of your table. This could be done by copying a simple formula to all blank cells in row A:

Code:
=A2

(That's how the formula would appear in cell A3)

Optionally, you could use a conditional format for the cells in column A that uses the same formula, and if true, applies the custom number format [b];;;[/b] which will make the text invisible on the sheet (it will still be seen in the formula bar)


Then, insure that column B is blank in the main employee record (so only dependent data appears in this column of your table)

----


Given one of the above (if suitable to you), and the answer to a couple questions, I can help you with a formula.

Q. In Column D, is the premium listed just on the main employee row, or is it listed on dependent rows too?

Q. Can you explain what you mean by recovery (amount I assume), and exactly how it's calculated


If you follow either of my restructuring recommendations, then an answer to the first part of your question ("How do I go about determining if the son/daughter against an employee is more than 1") is, you could use either of these formulas in the employee's main record row to count how many sons and daughters the employee has.  Include the worksheet name in front of $A:$A and $C:$C in the formula for the dependent table if it you split the dependents out to another sheet:

[code]=COUNTIFS($A:$A,$A2,$C:$C,"son")+COUNTIFS($A:$A,$A2,$C:$C,"daughter")

=SUMPRODUCT(--($A2=$A:$A),($C:$C="son")+($C:$C="daughter"))


The SUMPRODUCT version can be easily extended to do calculations based on the premium amount for each dependent. If you just want to add up the premium amounts for all the sons and daughters, you could use:

=SUMPRODUCT(--($A2=$A:$A),($C:$C="son")+($C:$C="daughter"),$D:$D)[/code]


Two articles from Chandoo about SUMPRODUCT:

What is Excel SUMPRODUCT formula and how to use it?

Advanced Sumproduct Queries


Hope this helps!

Asa
 
Asa,


Thanks a lot for the prompt reply. I am looking at your suggestions and would try to follow them step by step , so that I could automate the process without resorting to manually doing the process.


As for your questions-:


1. the premium is listed against the employee and his/her dependants.

2.The recovery amount is the amount that would be recovered from an employee. Only the premium related to employee, spouse and one child would be paid by the company. The rest would be recovered from an employee, to be paid to the Insurance company.


I just hope the solution offered by you would take care of the fact that it clearly distinguish between different employees and their depenadants. The data is continous and extends to over 1000 employee and 3000 dependants.


Thanks

Nitin G
 
Hi Nitin,


OK, so, if I follow you (plus my assumptions)--


Total Premium = employee premium + premium for each of his/her dependents.

All premiums are listed individually for each insured person covered.


Company Amount (of Premium) to Bear = employee premium + one husband/wife premium + one son or daughter premium

Recovery Amount = employee amount to bear = all other dependent's premiums

When deciding the Company Amount for child premiums, use the average of all the children's premiums.


The dependent's relationship to employee is one of the following:
Code:
spouse, son, daughter


~~~~~~~~~~~~~

Here's my suggested solution for the above understanding:

~~~~~~~~~~~~~~~

* Let's keep everything in the one table, but follow my previous instructions to include an employee # on every row ("mild" scenario #2)

* To keep the spreadsheet fast, lets try to minimize the number of multi-row calculations and their complexity. Breaking the calculation into smaller pieces and reusing the results (using additional "helper" columns) can aid in this endeavor. As well as in understanding and maintaining the formulas.


I've mocked up a sample spreadsheet that seems to do what you want.


7 new columns:

* Total Premium (uses SUMIF to add up all premiums for the given employee#)

* Spouses (uses COUNTIFS to count how many dependent spouses found)

* Spouse Premiums (uses SUMIFS to add up all premiums for employee's spouses)

* Children (uses COUNTIF to count how many rows have employee#; subtracts 1 for employee; subtracts number of Spouses previously calculated) -- faster than directly counting children

* Child Premiums (Total Premium - Employee Premium - Spouse Premiums) -- faster than direct calculation

* Recovery Amount (Total Premiums - Employee Premiums - Average of Child Premiums - Average of Spouse Premiums) -- Faster than direct calculation. Average Spouse/Child premium is the same as one child/spouses premium, splitting any premium differences evenly.

* Company Amount (Total Premiums - Recovery Amount)


In the mockup I also demonstrated conditional formatting to hide the employee numbers added in column A for all the dependents.


See my mockup for the details. Uses some Excel 2007+ features (if this is a problem, just let me know).


Insurance Premium Shared Responsibility Example.xlsx (click the download button one the preview loads in your browser)


Asa
 
Hi again Nitin,

I updated my mockup formulas to be significantly faster.


I tested with about 13,000 rows and the formulas I suggested yesterday, and it took roughly 10-20 seconds to do a full recalculation of the spreadsheet. Today's formulas--roughly 0.25 seconds !


Please download my sample again (same link) in the event you previously downloaded it.


I was able to speed up the formulas primarily by having them look for dependents in only the next 20 rows (to allow for up to 20 dependents) instead of searching the whole worksheet. I also leveraged the fact that the dependents are listed immediately below the employee in the worksheet, in one contiguous group-- a new formula counts the number of dependents, and the other formulas only search that many rows (and they don't need to check for the employee #, as it's established that these rows are part of the employee record).


I don't know if I took the BEST POSSIBLE strategy for speeding calculation, but the spreadsheet is fast now. If you required tens of thousands of rows, it would still be fast enough on a modern computer. The downside to my strategy is that it relies on the OFFSET() function to identify the dependents based on # of rows below employee. OFFSET is a "volatile" function in Excel, one of several function that cause cells dependent on them to be recalculated every time any change anywhere on the worksheet occurs... This could be avoided by simply modifying yesterday's formulas to search the next 20 rows instead of the whole worksheet, using relative references. I don't know which would perform better overall. The relative references could get messed up with adding and deleting of rows in the spreadsheet, whereas the offset reference will be sure to work as expected. Also, the multiple spouses support in my formulas could be unnecessary :).... I updated my mockup to include a sheet that only supports one spouse, and that sheet should be a little faster. Further speed optimization looks like it would be academic.


The new formulas:

* Number of Dependents (Uses MATCH to find the end of the dependent range. Change the "21" in the formula to the maximum number of dependents plus 1)

F2
Code:
=MATCH($A2,OFFSET($A2,,,21))-1


* Total Premium (Uses SUM to total employee and dependent premiums)

[b]E2 [code]=SUM(OFFSET($D2,,,$F2+1))


* Spouses (Uses COUNTIF to count spouses among dependents)

[b]G2 [code]=IF($F2=0,0,COUNTIF(OFFSET($C2,1,,$F2),"spouse"))


* Spouse Premiums (Uses SUMIF to total spouses premiums)

[b]H2 [code]=IF($F2=0,0,SUMIF(OFFSET($C2,1,,$F2),"spouse",OFFSET($D2,1,,$F2)))


* Children (Number of Dependents - Number of Spouses)

[b]I2[/b] [code]=$F2-$G2


* Child Premiums (Total Premium - Employee Premium - Spouse Premiums)

J2
=$E2-$D2-$H2[/code]


* Recovery Amount (Total Premiums - Employee Premiums - Average of Child Premiums - Average of Spouse Premiums)

L2[/b] =$E2-$D2-IF($I2=0,0,$J2/$I2)-IF($G2=0,0,$H2/$G2)[/code]


* Company Amount (Total Premiums - Recovery Amount)

K2[/b] =$E2-$L2[/code]


~~~~~~~~~~~~~~~~~~~~~~~~~~~~


For the One Spouse (if any) version, I made the following changes (column letters G:K are equivalent to H:L in original):


* Spouses - column is not needed, removed


* Spouse Premium (Uses VLOOKUP to find the spouse premium)

G2[/b] =IF($F2=0,0,IFERROR(VLOOKUP("spouse",OFFSET($C2:$D2,1,,$F2),COLUMNS($C2:$D2),FALSE),0))[/code]

* Children (Number of Dependents - [1 if any spouse premiums])

H2
Code:
=$F2-($G2<>0)

* Recovery Amount (Total Premiums - Employee Premiums - Average of Child Premiums - Spouse Premium)

K2[/b] [code]=$E2-$D2-IF($H2=0,0,$I2/$H2)-$G2


~~~~~~~~~~~~~~~~~~~~~~~~~


Finally, I adjusted the conditional format.


Originally I used my suggested formula (as for A2):

[code]=A2=A1

with the format:

;;;[/code]


That works great to hide the excess employee numbers, until you delete a row anywhere on the spreadsheet. That breaks the reference in the next row's conditional format rule, causing the employee# on that row to be shown regardless of whether it should or not.


Solution. Keep the "Offset" mood of the day going. Use this formula instead:

=A2=OFFSET(A2,-1,0)[/code]


I hope this is all similar to what you need. If not and/or you need help adapting it, just let me know.


Asa
 
Asa,


Thanks a ton!!!! My apologies for replying I'll late, bt it is quite neat nd effective solution


Jst 1 issue:


when I copy d formula down d sheet, it shows d value against d dependants which ideally it should not considering dat all information is captured in d rows corresponding to employee no when it 1st appears.


One caveat dat I have not been able to assess d example sheet since I m on phone and d sheet on d phone does not show d formulas!!!


Thanks a lot mate and I m Jst amazed hw nything can be achieved in excel!!! I wld like to be part of next excel school batch if I have ppl like u, Luke nd Hui to assist me to take care of nything nd everything in excel!!!
 
I am honored! Thanks for the complements.


I'm pretty new here and haven't gotten involved in the school yet myself. I'm sure others can comment on what to expect. I really like Chandoo's style and wealth of information.


Since the formulas only go in the main record line, not the dependent lines, here is a way to copy them down the sheet:

- AutoFilter the table (Data/Filter/Filter)

- Filter for blanks in Dependent #

- you should now see only the main employee records

- Copy the formulas

- Select down

- Paste

- Unfilter the list


You can use the same technique to fill the employee # field onto the dependent rows

- Autofilter

- Filter Dependent # is not blank

- in cell A3, put
Code:
=OFFSET(A3,-1,0)

- Copy/Paste down

- Unfilter


For employee #, when done entering the above formula, I suggest highlighting column A, hitting Copy, then Paste Special/Values to get rid of the formula since it won't be needed again and will just slow down the worksheet.


As to the not being able to see the formulas, please note that although the file is hosted on Google Docs, it is not saved as a Google document. The file needs to be downloaded to be worked with.


Your kind of appreciation is half the fun of solving problems here!

Asa
 
Back
Top