+ Reply to Thread
Results 1 to 5 of 5

Calculate average of time difference based on non-duplicate criteria

  1. #1
    Registered User
    Join Date
    07-08-2022
    Location
    Los Angeles, CA
    MS-Off Ver
    2016
    Posts
    12

    Calculate average of time difference based on non-duplicate criteria

    Hello,

    Can someone please help me come up with a formula to take the average of the difference between times in column C (C2:C16) and column B (B2:B16), but not include any duplicate times based on trades in column A (A2:A16)?

    Basically I am trying to calculate the average time a trade is held for, in one cell, C18. Column A is trade ID's with different trade $ amounts (not shown) which is why there's duplicate ID numbers. I would like to only find the difference between times based on each Trade ID once. Then I'd like to take the average of the entire difference of those times.

    The answer I'm looking for is in F2, but that was manually calculated. My attempt at a formula is in H2 but that's incorrect, you can ignore the rest of the spreadsheet. Please let me know if this is possible. Any help or guidance is much appreciated! Sample spreadsheet attached.
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,865

    Re: Calculate average of time difference based on non-duplicate criteria

    Power Query Solution

    Please Login or Register  to view this content.
    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,039

    Re: Calculate average of time difference based on non-duplicate criteria

    Try this:=SUMPRODUCT((C2:C16-B2:B16)*(A2:A16<>A3:A17))/SUM(1/COUNTIF(A2:A16,A2:A16))

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,577

    Re: Calculate average of time difference based on non-duplicate criteria

    Try this
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  5. #5
    Registered User
    Join Date
    07-08-2022
    Location
    Los Angeles, CA
    MS-Off Ver
    2016
    Posts
    12

    Re: Calculate average of time difference based on non-duplicate criteria

    Thank you alansidman, josephteh and kvsrinivasamurthy! I appreciate the quick response and help. Those formulas worked perfectly. Unfortunately I wasn't able to use the Power Query as I could not find the option to paste the code in a Blank Query on my version of Excel. Maybe because it's a Mac version?

    Nonetheless, the problem is solved. Thanks again!

+ 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. [SOLVED] calculate time difference based on date and time in different cells
    By s7yzrs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-27-2022, 06:22 AM
  2. [SOLVED] Conditional Formatting based on time difference between set criteria
    By Wolfieee in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 03-19-2019, 06:33 AM
  3. How to calculate Sum and Average based on criteria
    By Sanjibghosh in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-08-2017, 08:06 AM
  4. Calculate time difference based on working hours
    By stanlyj in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-31-2017, 08:39 AM
  5. [SOLVED] Identify the pair and calculate the time difference if certain criteria match
    By Chippi in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-10-2014, 07:00 AM
  6. Calculate Time Difference If With Multiple Criteria
    By gotsomekorn in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-04-2014, 03:50 PM
  7. Calculate average difference between two columns of data [if criteria is met]
    By samcdavies in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-29-2013, 04:56 AM

Tags for this Thread

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