Power Query Text.InferNumberType: How to Use It
In this article
Text.InferNumberType takes a column of text values and tells you the number type Power Query would assign if it converted that text to numbers. It does not change your data. You give it a text value or a text column, and it returns a type such as type number, type nullable number, type currency, or type any depending on what it finds. Use it when you are building a custom column, writing an M query by hand, or checking whether a column of imported text will survive a change-type step without errors. It is most useful on data that arrives as text from CSV files, web pages, or APIs where the original number formatting is unknown.
What You'll Need
- Power BI Desktop, Excel with Power Query, or another host that includes the Power Query engine. The function is part of the standard M library, so no add-in is required.
- A query with at least one text column, or a text literal you want to test.
- Access to the Power Query Editor and, for hand-written M, the Advanced Editor. Menu labels can differ slightly by version, device, or region.
- Basic familiarity with the M formula bar and with the difference between a value and a type.
Step-by-Step
- Load your data into Power Query. In Excel, select your table and choose Data > From Table/Range. In Power BI Desktop, choose Home > Get data and pick your source. Confirm the column you want to test is currently typed as text, shown by the ABC icon in the column header.
- Open the Power Query Editor. This is where the M code lives. If you loaded from Excel, the editor opens automatically; otherwise select Transform data.
- Add a custom column for the test. Go to Add Column > Custom Column. Give it a name such as InferredType. In the formula box, enter a call that passes your text column, for example
Text.InferNumberType([YourColumn]). Replace YourColumn with the exact header name, including any spaces inside square brackets. - Review the result. The new column shows a type value for each row, not a number. You will see entries like
type number,type nullable number,type currency, ortype any. A nullable type means the function found at least one blank or null in the sample it inspected. - Test individual values when you need certainty. In the formula bar you can run the function on a literal, for example
Text.InferNumberType("1,234.56"). This is handy for checking how a specific format is interpreted before you commit to a change-type step. - Use the result to decide your conversion. If the inferred type is a plain number or currency, a Change Type step using that type is likely to succeed. If it returns
type any, the column contains values the engine cannot treat as numbers, so clean those rows first or convert with a locale-aware option. - Remove the helper column before loading. Right-click the custom column header and choose Remove. The function was only a diagnostic; leaving it in adds a column of type values to your model.
- Apply the real conversion. Select the original text column, choose Transform > Data Type, and pick the type the function suggested. Alternatively, right-click the column header and choose Change Type > Using Locale if your data uses a regional format such as comma decimals.
Common Mistakes
- Expecting a converted number. Text.InferNumberType returns a type, not a value. If you want the number itself, use Number.FromText or a Change Type step instead.
- Passing a whole table or column object. The function expects a text value or a text list. Passing the column name without row context, or passing a table, produces an error.
- Ignoring locale. The inference uses the query's culture settings. Text like "1.234,56" may be read as a different number than you expect if the culture is set to a region that uses the opposite separators. Set the locale on the step or use Change Type > Using Locale.
- Assuming it validates data. The function samples and infers; it does not guarantee every row will convert. Rows with stray characters, currency symbols in unexpected places, or text like "N/A" can still fail later.
- Leaving the helper column in the output. The diagnostic column is not useful in a report and can confuse downstream steps that expect numeric fields.
Tips
- Run the function on a representative sample, not just the first few rows. Inference quality depends on what it sees.
- Use it as a quick check before a Change Type step on CSV imports, where columns often arrive as text with mixed formats.
- Combine it with Table.TransformColumnTypes when you are writing M by hand and want to choose the type programmatically.
- If you only need to know whether a value is numeric, Value.Is with a type check can be simpler than inferring a full type.
- Keep a copy of the original text column until your conversion step is verified, so you can compare and roll back.
Troubleshooting
The custom column shows an error. Check the column name spelling and confirm the column is text. If the header contains spaces, wrap it in square brackets exactly as shown in the editor. An error can also mean you passed a table instead of a value.
The result is always type any. The column likely contains blanks, text labels, or symbols the engine cannot parse as numbers. Filter or clean those rows, then test again.
The inferred type looks wrong for your region. Set the query culture or use Change Type > Using Locale with the correct country. Inference follows the culture in effect at that step.
The conversion still fails after the check. Inference is not a validation pass. Inspect the failing rows for non-breaking spaces, trailing characters, or mixed decimal separators, and clean them before converting.
The function is not recognized. Confirm you are in the Power Query Editor and not in a DAX formula bar. Text.InferNumberType is an M function and is not available in DAX.
Frequently Asked Questions
Does Text.InferNumberType convert my text to numbers?
No. It returns a type value describing what the text looks like. You still need a Change Type step or Number.FromText to produce actual numbers.
What is the difference between type number and type nullable number?
A nullable type means the function found blanks or nulls in the input. A non-nullable type means it did not. The distinction matters when you set column types later, because nullable columns accept nulls without error.
Can I use it on a whole column at once?
Yes, inside a custom column or a table transformation it evaluates row by row. You cannot pass an entire column object outside a row context and expect a single result.
Why does it return type currency for some values?
The engine infers currency when the text includes currency formatting or a decimal pattern consistent with a currency type. The result depends on the culture and the characters present.
Is it available in Excel and Power BI?
Yes, it is part of the shared Power Query M library used by both. Exact menu locations for adding custom columns can vary slightly between hosts and versions.
Should I leave the helper column in my query?
No. Remove it after you have decided on the conversion. It adds no value to the final table and can complicate later steps.