Forum Discussion

anupambit1797's avatar
anupambit1797
Iron Contributor
Oct 14, 2023
Solved

COUNT

Dear Experts,

                    Greetings!

                    In attached file names "COUNT"

We have 3 variables "D", "U" and "S"

2DU => means 1 D and 1 U

2SU => means 1 S and 1 U,

 

In the column AP/AQ/AR, I want the count of "D","U" and "S" respectively for each rows

 

Could you please share how we can achieve this?

 

Thanks in Advance,

Br,

Anupam

6 Replies

  • Patrick2788's avatar
    Patrick2788
    Silver Contributor

    anupambit1797 

    This is a 365 solution:

     

     

     

    =LET(
        height, ROWS(grid),
        width, 3,
        DUS, {"*D*", "*U*", "*S*"},
        CountDUS, LAMBDA(r, c,
            LET(
                ThisRow, TAKE(DROP(grid, r - 1), 1),
                Criteria, INDEX(DUS, c),
                DD, COUNTIF(ThisRow, "2DD_"),
                Total, COUNTIF(ThisRow, Criteria),
                IF(c = 1, DD + Total, Total)
            )
        ),
        MAKEARRAY(height, width, CountDUS)
    )
  • NikolinoDE's avatar
    NikolinoDE
    Platinum Contributor

    anupambit1797 

    To count the occurrences of "D," "U," and "S" in each row in columns AP, AQ, and AR, you can use the following Excel formulas. Assuming your data starts in row 2 (adjust the cell references accordingly if your data starts in a different row):

    In cell AP2, you can enter the following formula to count "D"s:

    =LEN(A2)-LEN(SUBSTITUTE(A2,"D",""))

    In cell AQ2, you can enter the following formula to count "U"s:

    =LEN(A2)-LEN(SUBSTITUTE(A2,"U",""))

    In cell AR2, you can enter the following formula to count "S"s:

    =LEN(A2)-LEN(SUBSTITUTE(A2,"S",""))

    Drag these formulas down in columns AP, AQ, and AR to apply them to each row in your dataset.

    These formulas work by first substituting the target character with an empty string in the original text and then subtracting the length of the modified text from the length of the original text. This counts the number of occurrences of the specific character in the cell.

    The text and steps were edited with the help of AI.

     

    My answers are voluntary and without guarantee!

     

    Hope this will help you.

    Was the answer useful? Mark as best response and Like it!

    This will help all forum participants.

    • anupambit1797's avatar
      anupambit1797
      Iron Contributor

      HiNikolinoDE , in your solution, seems the output is not correct.. as below , it should come 28 for the 1st row.. etc.

       

      or please correct me , if I mis-interpret the formula

       

      Thanks & Regards

      Anupam Shrivastava

       

Resources