To get unique values from a column in Power BI, the fastest way is to use the "Remove Duplicates" feature on the column in the Power Query Editor, or use the DISTINCT function in DAX for a calculated table. This guide walks you through both methods, plus how to handle common issues like blanks and case sensitivity.
What You'll Need
- A Power BI Desktop file (or the Power BI service) with a data model that contains a table with the column you want to extract unique values from.
- Basic familiarity with the Power Query Editor (for the first method) or the DAX formula bar (for the second method).
- Your data should be loaded into Power BI. If you haven't loaded it yet, go to Home > Get Data and choose your source.
Step-by-Step
Method 1: Using Power Query (Recommended for Data Cleaning)
- Open Power Query Editor: In Power BI Desktop, go to the Home tab and click Transform Data. This opens the Power Query Editor window.
- Select the table: In the left pane, click on the table that contains the column you want to work with. If you have multiple tables, make sure you select the correct one.
- Select the column: Click on the column header that you want to get unique values from. For example, if you have a "Products" column, click on that header.
- Remove duplicates: With the column selected, go to the Home tab in the Power Query Editor and click Remove Rows > Remove Duplicates. This will immediately remove all duplicate values from that column, leaving only unique values.
- Rename the column (optional): If you want to keep the original column name, you can rename it by double-clicking the column header and typing a new name, like "Unique Products".
- Close and apply: Click Close & Apply in the top-left corner to load the cleaned table back into Power BI. The table now contains only unique values in that column.
Method 2: Using DAX to Create a Calculated Table
If you don't want to modify your original table (e.g., you need the full data for other visuals), you can create a separate table that lists only the unique values.
- Open the DAX formula bar: In Power BI Desktop, go to the Modeling tab and click New Table. This opens a formula bar where you can type a DAX expression.
- Type the DAX formula: Enter a formula like this: Replace YourTableName with the actual name of your table (in single quotes if it has spaces) and Product with your column name. Press Enter.
- Verify the result: A new table will appear in the Fields pane. When you click on it, you'll see a single column with the unique values from your original column. You can now use this table in visuals, like a slicer or a dropdown.
Method 3: Using the "Group By" Feature (Alternative in Power Query)
- Open Power Query Editor as in Method 1.
- Select the column you want to get unique values from.
- Go to the Transform tab and click Group By.
- In the dialog, set the "Group by" field to your column name. For the "New column name", type something like "Count" and in "Operation" choose "Count rows". Click OK.
- This creates a table with one row per unique value in your column, along with a count of how many times each value appears. If you only need the values, you can delete the count column later.
Common Mistakes
- Forgetting to select the column before removing duplicates: If you don't select the column, Power Query will remove duplicates based on all columns, which may not give you the unique values you want.
- Using the wrong table name in DAX: If you type the table name incorrectly, you'll get an error. Use the field list to copy the exact table name.
- Ignoring blanks: If your column has blank cells, they will be treated as a unique value. You may want to filter them out first if you don't want blanks in your list.
- Case sensitivity: By default, Power Query is case-insensitive, so "Apple" and "apple" are considered the same. If you need case-sensitive unique values, you'll need to use a different approach, like adding an index column and using DAX.
Tips
- Use a calculated table for dynamic lists: If your data refreshes and new values appear, the calculated table using DISTINCT will automatically update to include new unique values. The Power Query method also updates on refresh, but you need to re-apply the query.
- Combine with other functions: You can use the unique values table as a dimension table in your data model, linking it to your fact table via a relationship. This is a common best practice for data modeling.
- Sorting: To sort the unique values alphabetically, click on the column header in the table view and choose sort ascending.
- Use the "Remove Empty" option: In Power Query, after selecting your column, you can go to the Home tab and click Remove Rows > Remove Blank Rows to get rid of blank entries before removing duplicates.
Troubleshooting
- The "Remove Duplicates" option is greyed out: Make sure you have selected a column header. If you have multiple columns selected, it will still work, but it will remove duplicates based on the combination of selected columns.
- The DAX formula returns an error: Check that you are using the correct table and column names. Also, ensure you are using the DISTINCT function correctly – it takes a single column reference. If you need unique combinations of multiple columns, use DISTINCT on a table expression like
DISTINCT(SUMMARIZE('Table', 'Table'[Col1], 'Table'[Col2])). - The unique values table is empty: This can happen if the column contains only blanks or if you have filtered the data in Power Query to exclude all rows. Check your data source and any applied filters.
- Performance issues with large data: If you have millions of rows, removing duplicates in Power Query can be slow. Try to filter the data to only the rows you need before removing duplicates, or consider using a DAX calculated table which may be faster.
- After refreshing, the unique values don't update: In Power Query, make sure you are not using a static reference. If you used "Group By", it will refresh correctly. For DAX, the table recalculates on refresh automatically.
Frequently Asked Questions
Can I get unique values from multiple columns at once?
Yes. In Power Query, select multiple columns (hold Ctrl and click each header) and then click Remove Duplicates. This will give you unique combinations of those columns. In DAX, use the SUMMARIZE function as shown above.
How do I get a count of unique values instead of the list?
Use the DISTINCTCOUNT function in a measure: Unique Count = DISTINCTCOUNT('Table'[Column]). This returns the number of unique values, not the list itself.
What is the difference between DISTINCT and VALUES in DAX?
Both return a list of unique values, but VALUES also includes a blank row if there are blanks in the column, while DISTINCT does not. For a simple unique list, DISTINCT is usually what you want.
Can I use unique values in a slicer?
Yes. If you create a calculated table with unique values, you can use that table's column in a slicer. This is a common way to create a dropdown filter that shows only available values.
Does removing duplicates in Power Query affect the original data?
No. Power Query works on a copy of the data loaded into the model. Your original source data (like an Excel file or database) is not changed. The transformation is applied when you load data into Power BI.
What if I have leading/trailing spaces in my data?
Power Query treats "Apple" and "Apple " as different values. To fix this, use the Trim transform on the column before removing duplicates. In Power Query, select the column, go to Transform > Format > Trim.