We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
What's the most efficient way to extract numbers from a column that has a combination of both numbers and text? E.g.
1
1234
"hello World"
0
"arbitrary text"
should return
1
1234
null
0
null
Is there an M / PowerQuery formula for this scenario equaivalent to the t-sql "try_cast" or "try_convert"?
Solved! Go to Solution.
In DAX you can use ISNUMBER.
OK I should have tested that first. You were actually on the right track anyway. ISERROR(VALUE(TableName[ColumnName])) will return true if the value isn't a number, false if it is a number.
In Power Query it's a two-step formula but you can nest them: Value.Is(Value.FromText([ColumnName]), Int64.Type) will return true if the row contains a number value, false if not.
Hi @sethsanu,
Adding to other’s post, to output the column to the your desired format, just create a new calculated column using this formula: Column 2 = IF(ISERROR(VALUE(Table1[Column1])),"null",Table1[Column1]), for more details, please check the following screenshot
Thanks,
Lydia Zhang
@Anonymous that would come out to be a text column wouldn't it? I think @sethsanu meant he wanted a null result for text rows, rather than the actual text "null" but I could be mistaken.
Correct - I need to do the exclusion prior to importing at the M level. Thanks KHoreman - the M query test works fine! (marked as solution)
In DAX you can use ISNUMBER.
OK I should have tested that first. You were actually on the right track anyway. ISERROR(VALUE(TableName[ColumnName])) will return true if the value isn't a number, false if it is a number.
In Power Query it's a two-step formula but you can nest them: Value.Is(Value.FromText([ColumnName]), Int64.Type) will return true if the row contains a number value, false if not.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 57 | |
| 38 | |
| 33 | |
| 19 | |
| 16 |
| User | Count |
|---|---|
| 67 | |
| 66 | |
| 40 | |
| 34 | |
| 25 |