Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

From 4 Calculated Columns to 1?

Are there any common tips/tricks for combining many calculations into one?

 

My Scenario:

 

I have these 4 calculated columns used to get my final result. I would like to be able to do all the calculations in one step ( So I don't have to store everything!). My first thought was just to make each step a variable, but I ran into problems doing that. I cant pass in variables as arguments when the functions take columns.

 

The "final result" column is the count of "Accepted" for each ContactID, but this should only include the Current Status which is based on the Max Date of each ECID (EventID + ContactID)

Here are the 4 Calculations:

ECID = Sheet1[EventID] & Sheet1[ContactID]

DateNeeded = CALCULATE(
              MAX(Sheet1[Date]),
              FILTER(Sheet1,Sheet1[ECID] = EARLIER(Sheet1[ECID]) ))


CurrentStatus = IF(Sheet1[Date] = Sheet1[DateNeeded],
                        IF(Sheet1[Status] = "Accepted",
                            "Accepted",
                        BLANK()))

FinalResult = CALCULATE(
            COUNT(Sheet1[CurrentStatus]),
            FILTER(Sheet1,Sheet1[ContactID] = EARLIER(Sheet1[ContactID])
            ))

And the Table:

EventIDContactIDStatusDateColumnECIDDateNeededCurrentStatusFinalResult
Event1AAcceptedFriday, January 01, 20164Event1A1/3/2016 0:00 4
Event1ACancelledSaturday, January 02, 20164Event1A1/3/2016 0:00 4
Event1AAcceptedSunday, January 03, 20164Event1A1/3/2016 0:00Accepted4
Event2AAcceptedMonday, January 04, 20164Event2A1/4/2016 0:00Accepted4
Event3AAcceptedTuesday, January 05, 20164Event3A1/5/2016 0:00Accepted4
Event4AAcceptedWednesday, January 06, 20164Event4A1/6/2016 0:00Accepted4
Event1BAcceptedThursday, January 07, 20164Event1B1/11/2016 0:00 2
Event2BAcceptedFriday, January 08, 20164Event2B1/12/2016 0:00 2
Event3BAcceptedSaturday, January 09, 20164Event3B1/9/2016 0:00Accepted2
Event4BAcceptedSunday, January 10, 20164Event4B1/10/2016 0:00Accepted2
Event1BCancelledMonday, January 11, 20164Event1B1/11/2016 0:00 2
Event2BCancelledTuesday, January 12, 20164Event2B1/12/2016 0:00 2
Event1CAcceptedWednesday, January 13, 20161Event1C1/14/2016 0:00  
Event1CCancelledThursday, January 14, 20161Event1C1/14/2016 0:00  

 

 

  • Hi Anonymous,

    After research and test, I can combine the for steps to two, I am unable to do all the calculations in one step. Becasue the IF function can not be used in COUNT function.

    I get the CurrentStatus column using the formula.

    CurrentStatus = IF(Sheet1[Date]=CALCULATE(
                  MAX(Sheet1[Date]),
                  FILTER(Sheet1,Sheet1[EventID] = EARLIER(Sheet1[EventID])&&Sheet1[ContactID]=EARLIER(Sheet1[ContactID]))),IF(Sheet1[Status]="Accepted","Accepted",BLANK()))


    Then use your last formula to get the final result.



    Best Regards,
    Angelia

2 Replies

  • v-huizhn-msft's avatar
    v-huizhn-msft
    Microsoft Employee

    Hi Anonymous,

    After research and test, I can combine the for steps to two, I am unable to do all the calculations in one step. Becasue the IF function can not be used in COUNT function.

    I get the CurrentStatus column using the formula.

    CurrentStatus = IF(Sheet1[Date]=CALCULATE(
                  MAX(Sheet1[Date]),
                  FILTER(Sheet1,Sheet1[EventID] = EARLIER(Sheet1[EventID])&&Sheet1[ContactID]=EARLIER(Sheet1[ContactID]))),IF(Sheet1[Status]="Accepted","Accepted",BLANK()))


    Then use your last formula to get the final result.



    Best Regards,
    Angelia

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks, that will work. :smileyvery-happy: