Custom Formula with Specific Functions

KhmerBoi1

New Member
Joined
Aug 12, 2014
Messages
30
I'm trying to assign values to specific characters then aggregate and summarize them. I was trying to use specific functions, SUM or SUMPRODUCT and CHOOSE.

For instance:
If you have a row as depicted below. Each column is a DAY within the month in which the person decided to carpool. I want to calculate the amount of One-Way Trips.
X = Round Trip (2 One-Way Trip) // M = Morning ONLY (1 One-Way Trip) // E = Evening ONLY (1 One-Way Trip) // Any Other Character is valued as a 0.
ABCDEFGHIJKL
XMEXXDPXXXX16

The amount of One-Way Trips for the above would be 16.

Is there a way to use SUM or SUMPRODUCT and the CHOOSE functions to accomplish this? The CHOOSE function would be CHOOSE(value, {0, 1, 2}) or something similar. I'm not sure how to loop through each column in the row and summarize each cell in the ROW range.

Thank you for your help ahead of time.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Perhaps this:
Book1
ABCDEFGHIJKL
1XMEXXDPXXXX16
Sheet1
Cell Formulas
RangeFormula
L1L1=SUMPRODUCT(((A1:J1="X")*2)+(A1:J1="M")+(A1:J1="E"))
 
Upvote 0
Perhaps this:
Book1
ABCDEFGHIJKL
1XMEXXDPXXXX16
Sheet1
Cell Formulas
RangeFormula
L1L1=SUMPRODUCT(((A1:J1="X")*2)+(A1:J1="M")+(A1:J1="E"))

Was I thinking about it wrong to try to use the CHOOSE function?

Would that have been overkill?

Not wanting to be picky, but while there is not specific reason, could the CHOOSE function have been used?
 
Upvote 0
Was I thinking about it wrong to try to use the CHOOSE function?

Would that have been overkill?

Not wanting to be picky, but while there is not specific reason, could the CHOOSE function have been used?
I'm not sure, I'll have to play with it some.
 
Upvote 0
You could use CHOOSE like this:
Book1
ABCDEFGHIJKL
1XMEXXDPXXXX16
2XMEXXDPXXXX16
Sheet1
Cell Formulas
RangeFormula
L1L1=SUMPRODUCT(((A1:J1="X")*2)+(A1:J1="M")+(A1:J1="E"))
L2L2=SUM(IFERROR(CHOOSE(LOOKUP(A2:J2,{"E","M","X"},{1,2,3}),1,1,2),0))


Though with the LOOKUP, you can get incorrect results if you have other single letters in the range. What version of Excel are you using?
 
Upvote 0
You could use CHOOSE like this:
Book1
ABCDEFGHIJKL
1XMEXXDPXXXX16
2XMEXXDPXXXX16
Sheet1
Cell Formulas
RangeFormula
L1L1=SUMPRODUCT(((A1:J1="X")*2)+(A1:J1="M")+(A1:J1="E"))
L2L2=SUM(IFERROR(CHOOSE(LOOKUP(A2:J2,{"E","M","X"},{1,2,3}),1,1,2),0))


Though with the LOOKUP, you can get incorrect results if you have other single letters in the range. What version of Excel are you using?

I'm using Microsoft Excel 2016 and newer. Sometimes Excel O365 through either the Web or TEAMS.

There is other single character letters but everything except "X, M, E" is valued as a 0.

Capture Full Month.PNG


Capture Codes.PNG
 
Upvote 0
Gotcha. Well when you use 365, you can use the option in L3, otherwise, I would stick with the sumproduct in L1 because it ignores those other values already. The lookup in L2 will try to match those values either way and return incorrect results.
Book1
ABCDEFGHIJKLM
1XMEXXDPXXXX16
2XMEXXDPXXXO15should be 14, but LOOKUP uses an approximate match
3XMEXXDPXXXO14
Sheet1
Cell Formulas
RangeFormula
L1L1=SUMPRODUCT(((A1:J1="X")*2)+(A1:J1="M")+(A1:J1="E"))
L2L2=SUM(IFERROR(CHOOSE(LOOKUP(A2:J2,{"E","M","X"},{1,2,3}),1,1,2),0))
L3L3=SUM(IFERROR(CHOOSE(XLOOKUP(A3:J3,{"E","M","X"},{1,2,3},0,0,1),1,1,2),0))
 
Upvote 0
Solution
Gotcha. Well when you use 365, you can use the option in L3, otherwise, I would stick with the sumproduct in L1 because it ignores those other values already. The lookup in L2 will try to match those values either way and return incorrect results.
Book1
ABCDEFGHIJKLM
1XMEXXDPXXXX16
2XMEXXDPXXXO15should be 14, but LOOKUP uses an approximate match
3XMEXXDPXXXO14
Sheet1
Cell Formulas
RangeFormula
L1L1=SUMPRODUCT(((A1:J1="X")*2)+(A1:J1="M")+(A1:J1="E"))
L2L2=SUM(IFERROR(CHOOSE(LOOKUP(A2:J2,{"E","M","X"},{1,2,3}),1,1,2),0))
L3L3=SUM(IFERROR(CHOOSE(XLOOKUP(A3:J3,{"E","M","X"},{1,2,3},0,0,1),1,1,2),0))
Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,987
Members
449,093
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top