Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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  

 

 

1 ACCEPTED SOLUTION
v-huizhn-msft
Employee
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.

1.PNG

Best Regards,
Angelia

View solution in original post

2 REPLIES 2
v-huizhn-msft
Employee
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.

1.PNG

Best Regards,
Angelia

Anonymous
Not applicable

Thanks, that will work. Smiley Very Happy

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.