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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,223,796
Messages
6,174,657
Members
452,575
Latest member
Fstick546

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