When preparing our data for analysis we often deal blank rows which oftern skew our analysis and visuals. Let’s explore how to efficiently filter out these empty entries using both Power BI and Power Query, ensuring your data is clean and ready for analysis.
Assumed data model: HR_Data (EmployeeID: Text, Name: Text, Department: Text, Salary: Currency, HireDate: Date)
Removing null rows in Power Query
As always, we prefer to manipulate the data as close as possible to its source. When we don’t have access to the actual data source being a SQL database, No SQL databases, Excel or other files, we’ll try to use cleanse the data in Power BI:
- Go to “Home” > “Edit Queries” to open the Power Query Editor.
- Select your “HR_Data” query.
- Go to “Home” > “Remove Rows” > “Remove Blank Rows”.
- If you need to remove rows with blanks in specific columns:
a. Select the relevant columns.
b. Right-click > “Remove Empty”.
- For a more customized approach, add a custom column:
= if [Name] <> null and [Department] <> null and [Salary] <> null and [HireDate] <> null then true else false
- Filter this column to keep only “true” values.
- Remove the custom column if no longer needed.
Filter empty rows in Power BI
- Open your report in Power BI Desktop.
- Select the table visual containing your data.
- In the Filters pane, locate the column you want to filter (e.g., “Name”).
- Click the dropdown arrow and select “Filter type” > “Advanced filtering”.
- In the advanced filter dialog, set the condition: “is not blank”.
- Click “Apply filter”.
For a more robust solution using DAX:
Filtered_HR_Data =
FILTER(HR_Data,
NOT(ISBLANK(HR_Data[Name])) &&
NOT(ISBLANK(HR_Data[Department])) &&
NOT(ISBLANK(HR_Data[Salary])) &&
NOT(ISBLANK(HR_Data[HireDate]))
)
This measure creates a filtered version of your table, excluding rows where any of the specified columns are blank.
What to do if something goes wrong?
- If rows aren’t being removed, check for whitespace characters – Use the TRIM() function in DAX or the Trim transformation in Power Query to remove leading/trailing spaces.
- Ensure date columns are properly formatted. Blank dates might be interpreted as actual values.
- For numerical columns, consider using ISBLANK() in combination with ISERROR() to catch both blank and error values.
- If filtering in Power Query affects relationships, update them in the model view after applying changes.