Forum Discussion
M Query filter on Value.FromText
So I have a column that I can't change to number but need to filter based on value.
I used the advanced editor to do this and it seems to work in preview, the "values" start where I want, but fails when I try to Close and Apply:
I've also tried to create a column that is the Value.From text and filter the custom column, which also fails. I am using Import Mode.
Any ideas?
9 Replies
- MarcelBeugCommunity Champion
If you want the results to be numeric, you need to adjust the data type to number (or whole number: Int64,Type).
Below some code with a few examples.
let Source = #table(type table[Account Number = text],{{"0000400099"},{"0000400100"},{"0000400101"},{"0000400102"}}), #"Filtered Rows" = Table.SelectRows(Source, each Value.FromText([Account Number]) >= 400100), #"Added Custom" = Table.AddColumn(#"Filtered Rows", "ValueFromText", each Value.FromText([Account Number])), #"Added Custom1" = Table.AddColumn(#"Added Custom", "NumberFrom", each Number.From([Account Number])), #"Duplicated Column" = Table.DuplicateColumn(#"Added Custom1", "Account Number", "Account Number - Copy"), #"Changed Type" = Table.TransformColumnTypes(#"Duplicated Column",{{"Account Number - Copy", Int64.Type}, {"ValueFromText", Int64.Type}, {"NumberFrom", Int64.Type}}) in #"Changed Type"- Aron_MooreSolution Specialist
That's the rub, I don't want (can't) have them be numeric. They're used in a hierarchy joining with another table. For the relationship and hierarchy to work, they need to remain text.
- MarcelBeugCommunity Champion
Your code is working fine with me and I can load the table without any issues.
Can you eloborate on "it fails": don't you get the desired results? Or what error message do you get?