+ Reply to Thread
Results 1 to 17 of 17

Using if formula for each instance in sumproduct

  1. #1
    Registered User
    Join Date
    12-13-2013
    Location
    Denmark
    MS-Off Ver
    Excel 365
    Posts
    17

    Using if formula for each instance in sumproduct

    Hello all

    I have a table with project information and I need to sum up the total turnover for the present year if certain criterias are met.

    I have criterias for selecting projects using sumproduct:
    Criteria 1: Status ="Ordre"
    Criteria 2: Department = "B"
    Criteria 3: Order date < present year

    sumproduct((Table1[Order sum])*(YEAR(Table1[start]<(YEAR(today()))*(Table1[Department]="B")*(Table1[Status]="Ordre")

    Then I have If statements for calculating the turnover for each of the projects I have found using the sumproduct formula.
    Basically I'm finding the project workdays in 2025 and dividing it by the total number of workdays for the project
    Criteria 1: If start<2025 and finish<2025 then 0
    Criteria 2: If start>2025 and finish>2025 then 0
    Criteria 3: If start=2025 and finish=2025 then Order sum
    Criteria 4: If start<2025 and finish=2025 then (order sum x workdays(01-01-2025; finish))/workdays(start;finish)
    Criteria 5: If start=2025 and finish>2025 then (order sum x workdays(start; 31-12-2025))/workdays(start;finish)
    Criteria 6: If start<2025 and finish>2025 then (order sum x workdays(01-01-2025; 31-12-2025))/workdays(start;finish)

    I know how to write this very long if statement and I know how to write the sumproduct statement, but I don't know how to combine them or if sumproduct is the right way to go with this.
    I have considered creating an extra column in my table for the if statement and then using sumproduct on this column, but the table is refreshed every day with new project data, and I'm not sure the new column will calculate new lines.

    I'm using Excel365
    I've attached a sample table for testing if needed.

    Can someone please help
    mlan
    Attached Files Attached Files

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,006

    Re: Using if formula for each instance in sumproduct

    Not sure what you looking for..

    maybe this...

    i've create columns for 2025 and 2026.

    Formula is the same only header year is different
    Attached Files Attached Files
    Never use Merged Cells in Excel

  3. #3
    Forum Contributor
    Join Date
    01-07-2025
    Location
    Iran
    MS-Off Ver
    2021
    Posts
    137

    Re: Using if formula for each instance in sumproduct

    I created a function called Turnover2025 using VBA, the code of which is below. You will also see the attached file where you can see the output of the calculations.

    PHP Code: 
    Function Turnover2025(startDate As DatefinishDate As DateorderSum As Double) As Double
        Dim ws2025Start 
    As Datews2025Finish As Date
        Dim totWorkdays 
    As LongpartWorkdays As Long
        
        ws2025Start 
    DateSerial(202511)
        
    ws2025Finish DateSerial(20251231)
        
        
    totWorkdays Application.WorksheetFunction.NetworkDays(startDatefinishDate)
        
        If 
    totWorkdays 0 Then
            Turnover2025 
    0
            
    Exit Function
        
    End If
        
        If 
    Year(startDate) < 2025 And Year(finishDate) < 2025 Then
            Turnover2025 
    0
        
    ElseIf Year(startDate) > 2025 And Year(finishDate) > 2025 Then
            Turnover2025 
    0
        
    ElseIf Year(startDate) = 2025 And Year(finishDate) = 2025 Then
            Turnover2025 
    orderSum
        
    ElseIf Year(startDate) < 2025 And Year(finishDate) = 2025 Then
            partWorkdays 
    Application.WorksheetFunction.NetworkDays(ws2025StartfinishDate)
            
    Turnover2025 orderSum partWorkdays totWorkdays
        
    ElseIf Year(startDate) = 2025 And Year(finishDate) > 2025 Then
            partWorkdays 
    Application.WorksheetFunction.NetworkDays(startDatews2025Finish)
            
    Turnover2025 orderSum partWorkdays totWorkdays
        
    ElseIf Year(startDate) < 2025 And Year(finishDate) > 2025 Then
            partWorkdays 
    Application.WorksheetFunction.NetworkDays(ws2025Startws2025Finish)
            
    Turnover2025 orderSum partWorkdays totWorkdays
        
    Else
            
    Turnover2025 0
        End 
    If
    End Function 
    Attached Files Attached Files

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,006

    Re: Using if formula for each instance in sumproduct

    Here I've extended for more years...

    Struggling with table so here is reference formula:

    =$B2*(NETWORKDAYS(MAX($C2,DATE(G$1,1,1)),MIN($D2,DATE(G$1,12,31)))>0)*NETWORKDAYS(MAX($C2,DATE(G$1,1,1)),MIN($D2,DATE(G$1,12,31)))/NETWORKDAYS($C2,$D2)

    If you look for example project 13 SUM over years is same as total.

    Please Login or Register  to view this content.
    File attached
    Attached Files Attached Files

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,006

    Re: Using if formula for each instance in sumproduct

    I've compared 2025 with MiNd_HuNT3r and result is same so use solution that you prefer.

  6. #6
    Registered User
    Join Date
    12-13-2013
    Location
    Denmark
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Using if formula for each instance in sumproduct

    Thank you all for your answers but it's not what I'm looking for.

    I know how to write the if fomula containing the networkday formula. That's not my problem.

    But I don't know how to combine it with the sumproduct formula.

    I want one cell containing the total turnover for 2025 for all projects in department B, where the turnover for each project is calculated using the if formula

    basically:
    find all projects in department B
    calculate 2025 turnover for each project
    sum up 2025 turnover for department B

    I can work around it by adding an extra column to my table calculating the if formula for each project and then do a sumproduct on this column.

    But I was hoping that I didn't have to add the extra column.

    I was also hoping not to use vba for this.

    It might not be sumproduct that's the best way, but some other combination of the if formula and a look up formula.

    Thank you

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,215

    Re: Using if formula for each instance in sumproduct

    I don't see where you shared the IF formula that you say you've already created.
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  8. #8
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,006

    Re: Using if formula for each instance in sumproduct

    Does Pivot table give you what you need?

    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    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
    30,677

    Re: Using if formula for each instance in sumproduct

    Projects per Department

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Amount per Project per Department

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    See attached
    Attached Files Attached Files
    Last edited by JohnTopley; 02-13-2025 at 07:59 AM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  10. #10
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,006

    Re: Using if formula for each instance in sumproduct

    Quote Originally Posted by JohnTopley View Post
    Amount per Project per Department
    =SUMIFS($B:$B,$C:$C,">="&DATE(2025,1,1),$C:$C,"<="&DATE(2025,12,31),$E:$E,J$1,$A:$A,J3)
    It's not just in current year.. It's a ratio of particular year and total.

    For example, full year 2024, 2025 and 2026 for 30.000 should be 10.000 in 2025, while you'll get 0.

    Half year 2024, full 2025, half 2026 for 30.000 should return 15.000.

    (Not days but workingdays)
    Last edited by zbor; 02-13-2025 at 07:33 AM.

  11. #11
    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
    30,677

    Re: Using if formula for each instance in sumproduct

    @Zbor: dooh!

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    For Start/Finish in 2025 then "Order Sum" (as above)

    Only to illustrate use of SUMIFS and list by Department/Project. Not all IF Conditions!
    Last edited by JohnTopley; 02-13-2025 at 07:54 AM.

  12. #12
    Forum Contributor
    Join Date
    01-07-2025
    Location
    Iran
    MS-Off Ver
    2021
    Posts
    137

    Re: Using if formula for each instance in sumproduct

    I calculated this by Python:

    PHP Code: 
    Total turnover for 2025 in department B20331955.380120993 

  13. #13
    Registered User
    Join Date
    12-13-2013
    Location
    Denmark
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Using if formula for each instance in sumproduct

    Just an update

    Due to other work issues I haven't had time to work any more on my issue.

    For now I'm using a helper column in my table with the very long if formula:

    =HVIS(OG(ÅR([@Opstart])<ÅR(IDAG());ÅR([@[Forventet ****]])<ÅR(IDAG()));0;HVIS(OG(ÅR([@Opstart])>ÅR(IDAG());ÅR([@[Forventet ****]])>ÅR(IDAG()));0;HVIS(OG(ÅR([@Opstart])=ÅR(IDAG());ÅR([@[Forventet ****]]=ÅR(IDAG())));[@Ordresum];HVIS(OG(ÅR([@Opstart])<ÅR(IDAG());ÅR([@[Forventet ****]]=ÅR(IDAG())));[@Ordresum]*ANTAL.ARBEJDSDAGE(DATO(ÅR(IDAG());1;1);[@[Forventet ****]];Helligdage)/ANTAL.ARBEJDSDAGE([@Opstart];[@[Forventet ****]];Helligdage);HVIS(OG(ÅR([@Opstart])=ÅR(IDAG());ÅR([@[Forventet ****]]>ÅR(IDAG())));[@Ordresum]*ANTAL.ARBEJDSDAGE([@Opstart];DATO(ÅR(IDAG());12;31);Helligdage)/ANTAL.ARBEJDSDAGE([@Opstart];[@[Forventet ****]];Helligdage);HVIS(OG(ÅR([@Opstart])<ÅR(IDAG());ÅR([@[Forventet ****]]>ÅR(IDAG())));[@Ordresum]*ANTAL.ARBEJDSDAGE(DATO(ÅR(IDAG());1;1);DATO(ÅR(IDAG());12;31);Helligdage)/ANTAL.ARBEJDSDAGE([@Opstart];[@[Forventet ****]];Helligdage);0))))))

    It's in danish but to help translate
    HVIS=IF
    OG=AND
    ÅR=YEAR
    IDAG=TODAY
    ANTAL.ARBEJDSDAGE=NETWORKDAYS
    DATO=DATE

    Then in another sheet I do my sumproduct on the helper column
    SUMPRODUCT((Tabel_SharePoint[omsætning indeværende år])*(ÅR(Tabel_SharePoint[Ordredato])<ÅR(IDAG()))*(Tabel_SharePoint[Afdelings chef]='One Pager'!$B$6))/1000

    For now that works, but just for a learning point of view it would still be nice to know if the IF formula can be integrated into the SUMPRODUCT formula

    Thanks for helping

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,215

    Re: Using if formula for each instance in sumproduct

    Better to provide a sample workbook, as formulae are automatically translated therein. Also, if you need further assistance, then you need to provide a workbook.

    Here's a translation:

    Please Login or Register  to view this content.
    https://en.excel-translator.de/translator/

  15. #15
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,006

    Re: Using if formula for each instance in sumproduct

    Can you upload example workbook? It will convert all formula name so we can check it.

  16. #16
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: Using if formula for each instance in sumproduct

    Danish in formulas!? For helvede mand!
    As a fellow scandi, the first thing I do on a new computer is set the Excel language to English, so much easier to search for help.
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  17. #17
    Registered User
    Join Date
    12-13-2013
    Location
    Denmark
    MS-Off Ver
    Excel 365
    Posts
    17

    Re: Using if formula for each instance in sumproduct

    Her is a sample workbook as requested

    mlan
    Attached Files Attached Files

+ 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] Remove Duplicate - Specific instance but keeping data from removed instance?
    By NewYears1978 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-22-2022, 12:59 PM
  2. Formula to only retrieve the first instance of something
    By oneblondebrow in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-04-2021, 06:13 AM
  3. Replies: 3
    Last Post: 05-07-2016, 04:48 PM
  4. Replies: 3
    Last Post: 07-15-2014, 09:50 AM
  5. finding the nth instance in a formula
    By ammartino44 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-22-2014, 05:12 AM
  6. formula to highlight every instance apart from first
    By Blake 7 in forum Excel General
    Replies: 2
    Last Post: 11-08-2010, 05:58 PM
  7. Return one instance using formula or filter
    By Pat in forum Excel General
    Replies: 1
    Last Post: 09-09-2005, 02: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