Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Table.ColumnsOfType: A How-To Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Table.ColumnsOfType returns a list of column names whose data types match the types you specify, letting you target columns dynamically instead of hard-coding names. You give it a table and a list of type values (such as type number or type text), and it hands back the names of every column that is one of those types. This is useful when a source adds or renames columns and you want your query to keep working without manual edits.

What You'll Need

  • Power Query available in Excel, Power BI Desktop, or another host that supports it.
  • A table already loaded or connected in the Power Query Editor (from a workbook, CSV, database, or other source).
  • Basic familiarity with the formula bar and the Advanced Editor, since this function is written as an M expression.
  • The exact type keywords you want to match, such as type number, type text, type date, or type any.

Step-by-Step

  1. Load your data into Power Query. In Excel, select your data and use Data > From Table/Range. In Power BI Desktop, use Home > Get data and pick your source. The Power Query Editor opens with a query step list on the right.
  2. Confirm the column types. Look at the small type icon in each column header. If a column shows ABC it is text; a calendar icon means date; 123 means whole number or decimal. Table.ColumnsOfType only matches types that are actually set on the columns, so fix any wrong types first by clicking the icon and choosing the right one.
  3. Open the Advanced Editor. On the Home tab, click Advanced Editor. You will see the M code for your query, ending with an in statement that names the last step.
  4. Add a new step that calls the function. After your last step, add a line such as:
    TypedColumns = Table.ColumnsOfType(PreviousStepName, {type number, type text}),
    Replace PreviousStepName with the actual name of the step you want to inspect. The function returns a list of column names, not the table itself.
  5. Point the in statement at the new step so you can preview the result: change in PreviousStepName to in TypedColumns. Close the Advanced Editor. The preview now shows a list of matching column names.
  6. Use the list in a follow-up step. Most people do not stop at the list. Wrap it in Table.SelectColumns to keep only those columns:
    KeptTyped = Table.SelectColumns(PreviousStepName, TypedColumns)
    Then set the in statement to in KeptTyped.
  7. Test with a changed source. Add a dummy column of a different type to your source, refresh, and confirm the query still returns the expected columns. This verifies the dynamic behavior works as intended.

Common Mistakes

  • Passing a single type instead of a list. The second argument must be a list, so write {type number}, not type number.
  • Expecting a table back. The function returns a list of names. If you try to preview it as a table, you will see a list, which is correct.
  • Using it on columns with type any. Columns left as type any will not match specific types like type number. Set explicit types first.
  • Mismatching type keywords. type number covers both whole numbers and decimals, but type date will not match a column typed as type datetime. Use the exact type you set on the column.
  • Forgetting to update the step name. If you rename steps, the reference inside the function call breaks and you get an error.

Tips

  • Use type any in the list if you want to catch columns that have not been typed yet, but be aware this can return more columns than expected.
  • Combine with Table.SelectColumns for a robust pattern: select columns by type, then rename or reorder them.
  • Keep a comment in the Advanced Editor explaining why you used type-based selection, so future editors understand the intent.
  • If you only need to check for one type, you can still pass a single-item list; there is no separate function for one type.
  • Remember that column order in the returned list follows the table's column order, which helps when you later reorder columns.

Troubleshooting

If the function returns an empty list, check that the columns actually have the types you specified. Click each column header and confirm the icon. If you see errors, verify the step name in the function call matches a step that exists and returns a table. If the query fails after adding Table.SelectColumns, make sure the list contains at least one column name; an empty list will cause an error because SelectColumns requires at least one column. If the preview shows a list but you expected a table, that is normal: add a step that converts or uses the list. If the Advanced Editor shows a syntax error, check for missing commas or braces around the type list.

Frequently Asked Questions

What does Table.ColumnsOfType actually return?

It returns a list of text values, each being the name of a column whose type matches one of the types you passed in.

Can I use it to select columns by type in one step?

Not directly. You call Table.ColumnsOfType to get the list, then pass that list to Table.SelectColumns in a separate step.

Does it work with custom types?

It works with the built-in type keywords such as type number, type text, type date, type datetime, type logical, and type any. Custom record or table types are not matched by this function.

Why does my column typed as whole number not match type number?

In Power Query, whole number and decimal are both subtypes of number, so type number should match them. If it does not, confirm the column type is actually set to a number type and not text.

Can I use it on a table with no rows?

Yes. The function inspects column metadata, so it works even when the table has zero rows, as long as the columns and their types are defined.

Is Table.ColumnsOfType available in all Power Query versions?

It is a standard M function included in Power Query for Excel and Power BI Desktop. Very old versions may not include it, so update your host application if the function is not recognized.