Forum Discussion
How to count rows with specific value in Power Query
- 2 years ago
Thanks Edhans.
I am creating this Row count column #"Added Custom 8" only after the custom column #"Added Custom 7" I created previously:
And I am creating the custom column from Add Column ribbon -> Custom Column and below is the code I have:
And when I click OK and run, getting the below error:
- 2 years ago
Text.Contains is wrong. It should be Text.Contains([Test], "No")
You have one argument with an equal sign. Get rid of that and replace with a comma, for 2 arguments.
edhans Thanks for your response. Your sample code works fine and I found the problem on my end.
The TEST column I have in my condition is another custom Added column which is not in the source.
Table.RowCount(
Table.SelectRows(Source,
each Text.Contains ([TEST], "No")))
So my question is how to create a custom column in Power Query to count rows in the table that has "No" value in another custom column?
Please help
Not sure I understand. Your Row Count/Table Select should be after you have this other custom column created. So look at this code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlSK1YlWSgKTyWAyBUymgsm0ovx0MIOAMjCZnp+ThsRFI2MB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t]),
AddNewColumn =
Table.AddColumn(
Source,
"New Column",
each if [Product] = "a" then "f" else [Product]
),
#"Added custom" =
Table.AddColumn(
AddNewColumn,
"Custom",
each
Table.RowCount(Table.SelectRows(AddNewColumn, each Text.Contains([New Column], "f")))
)
in
#"Added custom"
The #"Added Custom" column where the Row Count and Table Select Rows is happening is referencing the AddNewColumn staep above where a new column was created that changes the "a" to an "f"
So the count goes from 7 to 9.
Please post more than just a formula for your custom column. You'll notice I am posting the code from the advanced editor. We have no idea what steps are before and after your custom column function, and that knowledge is critical to building it correctly.
- PowerUser392 years agoFrequent Visitor
Thanks Edhans.
I am creating this Row count column #"Added Custom 8" only after the custom column #"Added Custom 7" I created previously:
And I am creating the custom column from Add Column ribbon -> Custom Column and below is the code I have:
And when I click OK and run, getting the below error:
- edhans2 years agoCommunity Champion
Text.Contains is wrong. It should be Text.Contains([Test], "No")
You have one argument with an equal sign. Get rid of that and replace with a comma, for 2 arguments.- PowerUser392 years agoFrequent Visitor
Ok I changed it and it worked but the result is basically the entire row count in the table and not based on the condition we have to count only the rows with "No" value in TEST column. I want the same DAX output (116) in Power Query and not the entire table row count which is 8940
Any other way of writing this to get the intended result edhans?