+ Reply to Thread
Results 1 to 6 of 6

Count consecutive duplicate values and then divide by that number

  1. #1
    Registered User
    Join Date
    01-12-2016
    Location
    London, England
    MS-Off Ver
    Office 2013
    Posts
    3

    Count consecutive duplicate values and then divide by that number

    Hi,

    Apologies in advance if this isn't completely clear, I'm new to the forum so not completely sure on all the format rules for these posts!

    I have a set of data that looks a little like the below:

    Company Cost Type Number of Sales Rate Spend
    Sky CPS 10 £30 £300
    Sky CPS 5 £20 £100
    Skoda Fixed 15 £200 £200
    Skoda Fixed 10 £200 £200
    Skoda Fixed 12 £200 £200
    Samsung CPS 10 £10 £100
    Volkswagen Fixed 3 £500 £500
    Volkswagen Fixed 4 £500 £500


    I already have a nice formula that looks at what the cost type is and then calculates the spend correctly for CPS (Cost Per Sale) records. The difficulty I have is that I want to be able to accurately recognise the Fixed price records. In my table you can see for example we have 3 consecutive records for Skoda for a fixed price deal they have for £200. In reality this doesn't mean my spend for that company should be £600 though, it's a fixed deal so it should be £200 total spend for all their sales here, which means I want my Spend column to take into account how many consecutive rows have Skoda in column A and then divide the 'Rate' of £200 by that figure. This would mean Skoda's spend per row should actually be £66.66 (200/3). Is there a formula that could do this for me?

    Please ask if there's anything I can do to clarify this.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,364

    Re: Count consecutive duplicate values and then divide by that number

    Try in E2 and copy down

    =IF(B2="Fixed",D2/COUNTIFS($A$2:$A$9,$A2,$B$2:$B$9,$B2),$C2*$D2)

  3. #3
    Registered User
    Join Date
    01-12-2016
    Location
    London, England
    MS-Off Ver
    Office 2013
    Posts
    3

    Re: Count consecutive duplicate values and then divide by that number

    Thanks John, that worked perfectly for my example. Could you explain for the less technically minded (me!) what exactly the formula is doing here to perform this calculation?

    Best,

    Jack

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,364

    Re: Count consecutive duplicate values and then divide by that number

    =IF(B2="Fixed",D2/COUNTIFS($A$2:$A$9,$A2,$B$2:$B$9,$B2),$C2*$D2)

    We check if the "Cost Type" (B2) is "fixed": if TRUE, then we divide rate (D2) by the number "fixed" for a given company


    COUNTIFS($A$2:$A$9,$A2,$B$2:$B$9,$B2) counts the matches on Company (A2) AND "Fixed" (B2) in the whole range so for Skoda we get 3 and Volkswagen we get 2.

    So even the if the data was not "sorted" we should still get the correct results.

    If Cost type is not Fixed (FALSE on IF test), we calculate "Number of Sales" x "Rate"

    Hope this helps.

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,364

    Re: Count consecutive duplicate values and then divide by that number

    =IF(B2="Fixed",D2/COUNTIFS($A$2:$A$9,$A2,$B$2:$B$9,$B2),$C2*$D2)

    We check if the "Cost Type" (B2) is "fixed": if TRUE, then we divide rate (D2) by the number "fixed" for a given company


    COUNTIFS($A$2:$A$9,$A2,$B$2:$B$9,$B2) counts the matches on Company (A2) AND "Fixed" (B2) in the whole range so for Skoda we get 3 and Volkswagen we get 2.

    So even the if the data was not "sorted" we should still get the correct results.

    If Cost type is not Fixed (FALSE on IF test), we calculate "Number of Sales" x "Rate"

    Hope this helps.

  6. #6
    Registered User
    Join Date
    01-12-2016
    Location
    London, England
    MS-Off Ver
    Office 2013
    Posts
    3

    Re: Count consecutive duplicate values and then divide by that number

    Perfect, thanks again John.

+ 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. count the number of consecutive values >=2
    By jomuir in forum Excel General
    Replies: 8
    Last Post: 03-03-2017, 12:59 PM
  2. Count only number of values within duplicate records
    By davidharper2005 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 07-14-2015, 03:40 AM
  3. [SOLVED] Count the number of duplicate values
    By DixieDoll11 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 12-02-2014, 05:12 PM
  4. Trying to count the number of occurrences of duplicate values
    By rahworks in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-11-2014, 02:55 PM
  5. Replies: 17
    Last Post: 06-27-2014, 04:25 PM
  6. Replies: 1
    Last Post: 03-28-2013, 01:48 PM
  7. Replies: 0
    Last Post: 06-15-2011, 09:46 AM

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