Power Query - count text in 4 columns

rsj88

New Member
Joined
Feb 20, 2018
Messages
38
Hi,

i have the below dataset of 3 columns i need the 4th column (custom colum) to count the how many times "red" appears in total.

I tried List.Cotainsall but this is just true and false.

Colour1Colour2Colour3Custom Column
redredblue2
blueredgreen1

Thanks again
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hello.
Variant
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    addRedCount = Table.AddColumn(Source, "Custom Column", each List.Count(List.Select(Record.FieldValues(_), each _ = "red")))
in
    addRedCount
Regards,
 
Upvote 0
Hi

Thanks this code is perfect.

if i want to tweak this to only count columns Colour2 and Colour3 would this be possible?

Thanks
 
Upvote 0
you can try with Custom Column: =List.Count(List.Select(List.LastN(Record.FieldValues(_), 2), each _ = "red"))
 
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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