Forum Discussion

tgjones43's avatar
tgjones43
Helper IV
7 years ago
Solved

Count text values across multiple columns for each row

Hello all, I have searched the forum for a solution to this but haven't managed to find what I need.

 

I have the following dataset and need to count the occurrences of each two letter code in columns [Spot 1] to [Spot 10] for each row. The result I'm hoping for is shown in the final 5 columns, as highlighted in bold.

 

SiteCategorySpot 1Spot 2Spot 3Spot 4Spot 5Spot 6Spot 7Spot 8Spot 9Spot 10NOEACLRSSC
AANONONONONONONONONONO10nullnullnullnull
ABEAEAEACLEAEAEAEACLEAnull82nullnull
BASCNONONONONONONONONO9nullnullnull1
BBRSRSRSRSCLCLRSRSRSRS,CLnullnull38null

 

It is complicated by there being some occurrences of two codes, separated by a comma, as you can see in the last row for [Spot 10].

 

I'd prefer to do this in the Query Editor. Any help would be greatly appreciated!

 

 

 

 

 

 

 

  • tgjones43 

     

    In that case

     

    =List.Count(
                     List.Select(
      Text.Split(
    Text.Combine(
    List.Transform(Record.ToList(_),each Text.From(_))
            ,",")
    ,
    ","
                    ),each _ ="CL")
    )