Forum Discussion
Count rows based on format
- 1 year ago
Hi Anonymous
You can try this in Power Query.
let Source = Table.FromColumns({ {1, 1, 1.2, 3, "x"} }, type table [Values = any]), AddType = Table.AddColumn(Source, "Data Type", each let v = [Values] in if Value.Is(v, Number.Type) then (if Number.Mod(v, 1) = 0 then "Integer" else "Number") else "Text", type text) in AddType1,1,1.2,3 and x are the sample values to test whether they're integer, number (with decimal) or a text. The custom column below is what does the checking.
let v = [Values] in if Value.Is(v, Number.Type) then (if Number.Mod(v, 1) = 0 then "Integer" else "Number") else "Text"
Hi Anonymous ,
In Power BI, column data types are enforced, so mixed data types usually result in errors during data transformation. The best way to count non-numeric values is in Power Query before loading the data. Use a custom column with try Number.From([YourColumn]) otherwise "Error" to flag invalid values. Then, filter or sum the occurrences of "Error" to count them. If Power Query coerces numbers into text instead of generating errors, use if Value.Is(Number.FromText([YourColumn]), type number) then 0 else 1 to detect non-numeric values. This ensures proper validation before the data reaches Power BI.
Best regards,