+ Reply to Thread
Results 1 to 11 of 11

DAX Function to Substitute Excel SumProduct involving multiple conditions

  1. #1
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    DAX Function to Substitute Excel SumProduct involving multiple conditions

    I have a fairly large table in Excel which is linked to my Power Pivot as data source.

    I have the following function in the Excel Table:

    =SUMPRODUCT(--(fdataTable1[Passenger phone number]=[@[Passenger phone number]]),--(fdataTable1[Completed Time]<[@[Completed Time]]))

    This function is making my Excel sheet run slow, therefore I was looking for a way to get rid of this column in the source excel file and instead create the same in Power Pivot as a Calculated Column.

    Some help would be appreciated.
    Last edited by ibuhary; 02-20-2018 at 07:02 AM. Reason: Solved

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: DAX Function to Substitute Excel SumProduct involving multiple conditions

    Hi,

    You can use something like the attached.

    I have had to paste the formula into a text file in an effort to bypass the forum's ridiculous firewall.
    Attached Files Attached Files
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: DAX Function to Substitute Excel SumProduct involving multiple conditions

    @xlnitwit - If you place a space behind each "<", you can post it:
    Please Login or Register  to view this content.
    Otherwise, Securi thinks it's HTML and rejects it.
    Last edited by leelnich; 02-20-2018 at 06:42 AM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: DAX Function to Substitute Excel SumProduct involving multiple conditions

    Thanks- I thought I had tried that, but perhaps not. I seemed to be blocked from the site for about 10 minutes after a few attempts so maybe that was the problem.

  5. #5
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: DAX Function to Substitute Excel SumProduct involving multiple conditions

    Thanks a lot, it works fine.

    I was trying to use Calculate or Countx etc... but none of it works

  6. #6
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: DAX Function to Substitute Excel SumProduct involving multiple conditions

    @xlnitwit - could you please explain me on this function few things:
    1. why is that we have to use - & & twice; and
    2. Also why do we have to use < & earlier together as < earlier

    appreciate any help

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: DAX Function to Substitute Excel SumProduct involving multiple conditions

    && is the operator equivalent of the AND function.
    You have to use < because you want to count items with an earlier completed time. The EARLIER function allows you to use the earlier row context (the current row in the table) when iterating through each row in the table using FILTER.

  8. #8
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: DAX Function to Substitute Excel SumProduct involving multiple conditions

    So does this mean that if I change the order of the rows in source data the function will give me a different answer. I mean the Data is now sorted as most recent records on top and earlier records last.

    If for some reason if we change the Source Table Sort Order what will happen?

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: DAX Function to Substitute Excel SumProduct involving multiple conditions

    The table order is irrelevant. The EARLIER function does not relate to row order but to the row context for evaluation.

    For a calculated column, the formula is evaluated for each row in the table. That is the primary row context.

    In this formula, we filter the table evaluating each row against some criteria- that creates a second row context. In order to compare each row in this second context against the value from the first context, we use the EARLIER function to return the value from the first context. It doesn't mean that only rows that come before the current row in the table are considered.

    It's a little bit like using the @ symbol in a structured table reference to mean 'this row' rather than the entire column.

  10. #10
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: DAX Function to Substitute Excel SumProduct involving multiple conditions

    Okay thanks for that tip, there is soooooooooooo much to learn that we dont know.

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: DAX Function to Substitute Excel SumProduct involving multiple conditions

    Quote Originally Posted by ibuhary View Post
    there is soooooooooooo much to learn that we dont know.
    Too true- especially as the BI features in Excel are a moving target! Case in point, if you have Excel 2016 you could use VAR instead of EARLIER.
    Last edited by xlnitwit; 02-20-2018 at 10:16 AM.

+ 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. =SUMPRODUCT with multiple conditions
    By maxhecht2 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-24-2017, 10:22 AM
  2. [SOLVED] Sumproduct with multiple conditions
    By rowena229 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-16-2014, 09:36 AM
  3. Excel formula to sumproduct but with multiple conditions
    By Dani8826 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-07-2014, 04:25 AM
  4. Replies: 8
    Last Post: 07-17-2013, 02:13 PM
  5. [SOLVED] Complex IF function involving matching multiple criteria
    By adray13 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-25-2013, 03:05 PM
  6. Replies: 0
    Last Post: 09-29-2012, 12:27 AM
  7. Multiple (3) SUMPRODUCT conditions
    By timjames in forum Excel General
    Replies: 2
    Last Post: 11-03-2011, 03:17 PM

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