Forum Discussion
How to ignore a column when counting in Power Query
Hi all
I have a table of >1000 rows, with each row looking like this:
| Index | Spot 1 | Spot 2 | Spot 3 | Spot 4 | Spot 5 | Spot 6 | Spot 7 | Spot 8 | Spot 9 | Spot 10 | Spot 11 | TICK | NO TICK |
| 1 | TICK | TICK | TICK | TICK | TICK | TICK | TICK | TICK | TICK | TICK | TICK | 11 | 0 |
| 2 | NO TICK | NO TICK | NO TICK | NO TICK | NO TICK | NO TICK | NO TICK | NO TICK | NO TICK | NO TICK | NO TICK | 0 | 11 |
Where the last 2 columns add the number of TICK and NO TICK values for each row using this code (for NO TICK):
= Table.AddColumn(#"Replaced Value #2.1", "NO TICK", each List.Count(
List.Select(
Text.Split(
Text.Combine(
List.Transform(Record.ToList(_),each Text.From(_))
,",")
,
","
),each _ ="NO TICK")
))
but what I'd like to do is ignore whatever is in the column Spot 11, so in the example above the figures would be 10 not 11 in the last 2 columns.
What is the easiest way to do this?
Thank you!
tgjones43 , You can use List.RemoveLastN and remove last element of the list
https://docs.microsoft.com/en-us/powerquery-m/list-removelastn
3 Replies
- amitchandak
Super User
tgjones43 , You can use List.RemoveLastN and remove last element of the list
https://docs.microsoft.com/en-us/powerquery-m/list-removelastn
- tgjones43
Helper IV
Thanks amitchandak do you know how to fit that command into the code that I pasted? I can't work this out.
- tgjones43
Helper IV
I figured it out, pasting the code below in case it is useful to anyone else:
= Table.AddColumn(#"Replaced Value #2.1", "NO TICK", each List.Count(
List.Select(
Text.Split(
Text.Combine(
List.Transform(List.RemoveLastN(Record.ToList(_),1),each Text.From(_))
,",")
,
","
),each _ ="NO TICK")
))