+ Reply to Thread
Results 1 to 21 of 21

Formula for start data and end dates to match year

  1. #1
    Registered User
    Join Date
    08-26-2015
    Location
    Egypt
    MS-Off Ver
    2016, Office 365
    Posts
    39

    Question Formula for start data and end dates to match year

    I have sheet with this data

    No., S_date, E_date, Monthly_rent, (years) and total

    I need when write S_date and E_date, sum of each year is calculated separately. How can do it?


    Thanks for support me
    Attached Files Attached Files
    Last edited by ahmadhassan; 07-09-2019 at 03:26 PM. Reason: Change title

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: Q: formulas dates (if)

    If I understand correctly, try in B2 copied down and to the right...

    =IF(AND(E$1>=YEAR($B2),E$1<=YEAR($C2)),$D2,"")
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    08-26-2015
    Location
    Egypt
    MS-Off Ver
    2016, Office 365
    Posts
    39

    Re: Q: formulas dates (if)

    Quote Originally Posted by jeffreybrown View Post
    If I understand correctly, try in B2 copied down and to the right...

    =IF(AND(E$1>=YEAR($B2),E$1<=YEAR($C2)),$D2,"")
    Thanks for help me but is wrong

    The S_date is 01/04/2016 and E_date 15/06/2023 and monthly rent is 200$, So yearly is for:

    2016 = "1800", 2017 = "2400", 2018 = "2400", 2019 = "2400", 2020 = "2400", 2021 = "2400", 2022 = "2400" and 2023 = "1200"

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: Q: formulas dates (if)

    Quote Originally Posted by ahmadhassan View Post
    Thanks for help me but is wrong
    I would respectively disagree with this statement.

    I did say if I understood correctly, so what would help, please update your worksheet with what you expect for the entire table. E2:N4.

  5. #5
    Registered User
    Join Date
    08-26-2015
    Location
    Egypt
    MS-Off Ver
    2016, Office 365
    Posts
    39

    Re: Q: formulas dates (if)

    Quote Originally Posted by jeffreybrown View Post
    I would respectively disagree with this statement.

    I did say if I understood correctly, so what would help, please update your worksheet with what you expect for the entire table. E2:N4.
    Updated sheet with data
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Formula for start data and end dates to match year

    Test my attachment.
    Best Regards,
    Maras.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    08-26-2015
    Location
    Egypt
    MS-Off Ver
    2016, Office 365
    Posts
    39

    Re: Formula for start data and end dates to match year

    Quote Originally Posted by maras_mak View Post
    Test my attachment.
    Best Regards,
    Maras.
    Thanks Maras that is required, also I need explain if S_date from 1 to 15 of month also E_date from 16 to last month equal half month
    And if you have time and fast explain formula to learn.
    Thanks again

  8. #8
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: Formula for start data and end dates to match year

    In the attachment, my corrected formulas according to your needs.
    Best Regards,
    Maras.
    Attached Files Attached Files

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,558

    Re: Formula for start data and end dates to match year

    Sorry for off-topic interjection:

    @Maras Mak

    Although there is no official rule regarding this behaviour, we request that wherever possible both the question AND the answer be provided in substantive detail here within the thread. An attached workbook is an excellent aid for posing a question and offering a solution, but solely doing that with no in thread explanation makes it difficult for researchers to understand or consider the Q & A of this thread without downloading what may be a pointless doc to them, if they can do that at all. Doing that also hides the content from search engines so others may never benefit from this.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  10. #10
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Formula for start data and end dates to match year

    =AND(YEAR($B4)<=E$1,YEAR($C4)>=E$1)*$D4*(12-IF(AND(YEAR($B4)=E$1,DAY($B4)>15),MONTH($B4)-0.5,IF(YEAR($B4)=E$1,MONTH($B4)-1,0))-IF(AND(YEAR($C4)=E$1,DAY($C4)<=15),13-MONTH($C4)-0.5,IF(YEAR($C4)=E$1,12-MONTH($C4),0)))

    firstly is the year in the range of rental contract AND(YEAR($B4)<=E$1,YEAR($C4)>=E$1) if this is not the case everything is 0

    rent is monthly rental * months


    if we start at 12 months, we need to remove months from this figure if the rental starts partway through the year
    IF(AND(YEAR($B4)=E$1,DAY($B4)>15),MONTH($B4)-0.5,IF(YEAR($B4)=E$1,MONTH($B4)-1,0))

    if the start date was for example 15/4/16 we would take away MONTH($B4)-1 months = 3 months (Jan- mar)

    if the start date was for example 15/4/16 we would take away MONTH($B4)-0.5 months 3.3 months (Jan- to half april)


    Similar has to happen at the end of the rental
    if the end date was for example 15/6/23 we would take away 13-MONTH($C4)-0.5 months 6.5 months (half june-Dec)
    if the end date was for example 16/6/23 we would take away 12-MONTH($C4) months 6 months ( july-Dec)

    if the year does not have the start or the end of the contract in it it is just 12 * monthly rental with no subtractions

  11. #11
    Registered User
    Join Date
    08-26-2015
    Location
    Egypt
    MS-Off Ver
    2016, Office 365
    Posts
    39

    Re: Formula for start data and end dates to match year

    Quote Originally Posted by maras_mak View Post
    In the attachment, my corrected formulas according to your needs.
    Best Regards,
    Maras.
    Yes Maras, I need formula calc such as example results

  12. #12
    Registered User
    Join Date
    08-26-2015
    Location
    Egypt
    MS-Off Ver
    2016, Office 365
    Posts
    39

    Re: Formula for start data and end dates to match year

    Quote Originally Posted by davsth View Post
    =AND(YEAR($B4)<=E$1,YEAR($C4)>=E$1)*$D4*(12-IF(AND(YEAR($B4)=E$1,DAY($B4)>15),MONTH($B4)-0.5,IF(YEAR($B4)=E$1,MONTH($B4)-1,0))-IF(AND(YEAR($C4)=E$1,DAY($C4)<=15),13-MONTH($C4)-0.5,IF(YEAR($C4)=E$1,12-MONTH($C4),0)))
    Thanks Davsth,
    Can explain me, if I need edit on your formula and calc by date of month such
    S_date is 20/4/2014 and E_date in 16/01/2023 the result is in Jan 2023 is 533.33 "If monthly rent 1000$"
    Attached Files Attached Files
    Last edited by ahmadhassan; 07-14-2019 at 06:56 PM.

  13. #13
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Formula for start data and end dates to match year

    its a little unclear, your example of halfs was confusing earlier inthe thread

    =AND(YEAR($B2)<=E$1,YEAR($C2)>=E$1)*$D2*(12-IF(AND(YEAR($B2)=E$1,DAY($B2)>15),MONTH($B2)-0.5,IF(YEAR($B2)=E$1,MONTH($B2)-1,0))-IF(AND(YEAR($C2)=E$1,DAY($C2)<=15),13-MONTH($C2)-0.5,IF(YEAR($C2)=E$1,12-MONTH($C2),0)))

    first month proportion
    1-(DAY($B2)-1)/DAY(EOMONTH($B2,0))

    Last month proportion
    =(DAY($C2))/DAY(EOMONTH($C2,0))

    Jan isn't 533 as there are 31 days in January

    and 20/4 is the last 11 days in April
    Last edited by davsth; 07-16-2019 at 07:39 AM.

  14. #14
    Registered User
    Join Date
    08-26-2015
    Location
    Egypt
    MS-Off Ver
    2016, Office 365
    Posts
    39

    Re: Formula for start data and end dates to match year

    Quote Originally Posted by davsth View Post
    first month proportion
    1-(DAY($B2)-1)/DAY(EOMONTH($B2,0))

    Last month proportion
    =(DAY($C2))/DAY(EOMONTH($C2,0))

    Jan isn't 533 as there are 31 days in January

    and 20/4 is the last 11 days in April
    Thanks Davsth and I apologize for confusing, but can you tell me an example of a complete formula, or where this part is changed in the previous formula
    1-(DAY($B2)-1)/DAY(EOMONTH($B2,0))

    Last month proportion
    =(DAY($C2))/DAY(EOMONTH($C2,0))

  15. #15
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Formula for start data and end dates to match year

    the proportion of the month just gets multiplied by the month, so both formulas as multiplied by 2
    1-(DAY($B2)-1)/DAY(EOMONTH($B2,0))*d2

    Last month proportion
    =(DAY($C2))/DAY(EOMONTH($C2,0))*d2

  16. #16
    Registered User
    Join Date
    08-26-2015
    Location
    Egypt
    MS-Off Ver
    2016, Office 365
    Posts
    39

    Re: Formula for start data and end dates to match year

    Quote Originally Posted by davsth View Post
    the proportion of the month just gets multiplied by the month
    Thanks Bro,
    Exactly this formulas works with me, but in the first and last cell only.

    But how to put this formulas (First & Last month )
    =(DAY($B2)-1)/DAY(EOMONTH($B2,0))*d2

    =(DAY($C2))/DAY(EOMONTH($C2,0))*d2
    within full formula in other cell to work on all cells.

    I put final result on attached
    Attached Files Attached Files
    Last edited by ahmadhassan; 07-18-2019 at 01:03 PM.

  17. #17
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Formula for start data and end dates to match year

    Perhaps
    =(if(and(year($b2)<=e$1,year($c2)>=e$1),12,0)-if(year($b2)=e$1,month($b2)-1+(day($b2)-1)/day(eomonth($b2,0)),0))*$d2

  18. #18
    Registered User
    Join Date
    08-26-2015
    Location
    Egypt
    MS-Off Ver
    2016, Office 365
    Posts
    39

    Re: Formula for start data and end dates to match year

    Quote Originally Posted by davsth View Post
    Perhaps
    =(if(and(year($b2)<=e$1,year($c2)>=e$1),12,0)-if(year($b2)=e$1,month($b2)-1+(day($b2)-1)/day(eomonth($b2,0)),0))*$d2
    Work on S_date but in E_date not work

  19. #19
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Formula for start data and end dates to match year

    =(IF(AND(YEAR($B2)<=E$1,YEAR($C2)>=E$1),12,0)-IF(YEAR($B2)=E$1,MONTH($B2)-1+(DAY($B2)-1)/DAY(EOMONTH($B2,0)),0)-IF(YEAR($C2)=E$1,13-MONTH($C2)-(DAY($C2))/DAY(EOMONTH($C2,0)),0))*$D2

    Any better

  20. #20
    Registered User
    Join Date
    08-26-2015
    Location
    Egypt
    MS-Off Ver
    2016, Office 365
    Posts
    39

    Re: Formula for start data and end dates to match year

    Quote Originally Posted by davsth View Post
    =(IF(AND(YEAR($B2)<=E$1,YEAR($C2)>=E$1),12,0)-IF(YEAR($B2)=E$1,MONTH($B2)-1+(DAY($B2)-1)/DAY(EOMONTH($B2,0)),0)-IF(YEAR($C2)=E$1,13-MONTH($C2)-(DAY($C2))/DAY(EOMONTH($C2,0)),0))*$D2

    Any better
    Many thanks bro Davsth

  21. #21
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Formula for start data and end dates to match year

    To try and explain if a start year is equal to or less than the year, and the end year is greater than or equal to the end year, then you charge rent. If the year in question is in the middle this is easy as the rent is 12 * D2 (monthly rent)
    If the year is the start or end year (or both) this becomes a little more complicated

    at the start we would take away the number of months -1 from the 12, so if it was an April start we would remove 3 months, we would also need to remove the proportion of the month that had already happened. so if it was the 10th of April as the start
    (DAY($B2)-1)/DAY(EOMONTH($B2,0))



    we would wish to remove 9/30ths (10-1)/days in April

    A similar thing needs to take place at the end of the period

    We need to remove the months with no rent
    13-MONTH($C2) so if the end was 20 th october, we would remove 3 months

    we then would need to add on the days in the month rent could be charged
    DAY($C2))/DAY(EOMONTH($C2,0)

    =20/31

    so in a rental from 10th April to 20 October

    we would charge (12- ( 3+ (9/30))-(3-20/31)=6.34161 months rent

    Any clearer

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 09-06-2018, 10:54 PM
  2. [SOLVED] Year-to-Date Sums and Averages with different start dates
    By rachelglusk in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-29-2015, 07:13 PM
  3. [SOLVED] Require a formula to see if 2 dates fall within Year end and Start
    By john dalton in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-06-2014, 09:12 AM
  4. [SOLVED] Macro to Retrieve Data with Start Year and End Year
    By boldcode in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2013, 01:09 PM
  5. Replies: 3
    Last Post: 08-14-2012, 05:14 AM
  6. Calculate rate increases based on financial year and start dates
    By cowproduct in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-03-2012, 08:25 AM
  7. Sum of wages for the year with varying start dates
    By Ainsley in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-26-2007, 12:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1