+ Reply to Thread
Results 1 to 6 of 6

Using a function in an IF/THEN function?

  1. #1
    Registered User
    Join Date
    11-16-2018
    Location
    London, UK
    MS-Off Ver
    Office 2016 (16.0)
    Posts
    6

    Using a function in an IF/THEN function?

    Hi all,

    I have a problem analysing some biological data which describes the movement of different individual particles over time.

    Some example data below (and example excel attached):

    Particle Time (s) X Y Displacement (µm)
    1 0 19.1 32.8 #VALUE!
    1 1 19.1 32.7 0.05
    1 2 19.1 32.8 0.11
    1 3 19.0 32.8 0.04
    1 4 19.0 32.9 0.06
    1 5 19.1 32.7 0.17
    1 6 19.1 32.8 0.11
    2 0 33.1 30.6 14.22
    2 1 33.1 30.6 0.03
    2 2 33.1 30.6 0.00
    2 3 33.1 30.6 0.02
    2 4 33.1 30.6 0.04
    2 5 33.2 30.6 0.06

    I am interested in calculating the displacement of the particles over time, so using the X/Y values, I derive the displacement in column D using the X/Y values for the particle at t = x and x-1, e.g. =SQRT(((C3-C2)^2)+((D3-D2)^2))

    However, using this formula alone, I get large displacement values in between the last time point of one particle, and the first time point of the next particle. e.g. see Particle 2, Time 0 above - The displacement highlighted in bold should = 0, as with all future particles where time = 0.

    To get around this, I thought of using the IF/THEN function, so if time = 0, the displacement also = 0, and in other cases, use the formula above to calculate displacement.

    e.g. =IF(B9=0,"0","=SQRT(((C6-C5)^2)+((D6-D5)^2))")

    Using a formula in the IF/THEN function doesn't seem to work for me. Is this possible?

    If not, does anyone have any suggestions for a formula that achieve what I would like? In the real data there would be thousands of rows of data so doing the analysis wouldn't be a viable option...

    Apologies for the ramble, I hope that makes sense, but please ask for any clarification.

    Thanks!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    10-15-2018
    Location
    Iran
    MS-Off Ver
    2013
    Posts
    30

    Re: Using a function in an IF/THEN function?

    Hi,
    You have added an "="
    Do you mean this?
    PHP Code: 
    =IF(B2=0,0,SQRT(((C2-C1)^2)+((D2-D1)^2))) 
    Last edited by Hesamexcel; 11-16-2018 at 06:16 AM.

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,419

    Re: Using a function in an IF/THEN function?

    Use this:

    =IF(B2=0,0,SQRT(((C2-C1)^2)+((D2-D1)^2)))
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  4. #4
    Registered User
    Join Date
    11-16-2018
    Location
    London, UK
    MS-Off Ver
    Office 2016 (16.0)
    Posts
    6

    Re: Using a function in an IF/THEN function?

    Hi, thank you so much for the speedy response! The code works perfectly!

    I wonder, whether you may be able to help me with a follow-up question now.

    If I would now like to sum the displacements of each particle in a separate column, would there be a simple formula for that?

    Cheers!

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,419

    Re: Using a function in an IF/THEN function?

    Yes. With a listof particle numbers, starting in K2, use this in L2:

    =SUMIF(A:A,K2,E:E)

    You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.

  6. #6
    Registered User
    Join Date
    11-16-2018
    Location
    London, UK
    MS-Off Ver
    Office 2016 (16.0)
    Posts
    6

    Re: Using a function in an IF/THEN function?

    Quote Originally Posted by Glenn Kennedy View Post
    Yes. With a listof particle numbers, starting in K2, use this in L2:

    =SUMIF(A:A,K2,E:E)

    You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.
    Amazing, that's so helpful! Thank you so much

+ 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. COUNTUNIQUE Function in Google Sheets; Excel lacks a direct counterpart to this function?
    By PivotTablePSHomage in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-18-2018, 05:27 AM
  2. Replies: 3
    Last Post: 08-14-2017, 06:26 AM
  3. Calling function inside function. (aka nested function)
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2015, 05:58 AM
  4. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  5. Replies: 2
    Last Post: 01-15-2014, 11:40 PM
  6. Replies: 1
    Last Post: 03-21-2012, 11:22 AM
  7. [SOLVED] Excel - User Defined Function Error: This function takes no argume
    By BruceInCalgary in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2006, 04:05 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