Column operations (rename, remove, reorder) in Power BI - Real Business Scenario
| OrderID | CustomerName | ProductCode | ProductName | QuantitySold | SaleDate | SalesRep | Region | DiscountApplied |
|---|---|---|---|---|---|---|---|---|
| 1001 | John Smith | P100 | Notebook | 5 | 2024-05-01 | Alice | East | Yes |
| 1002 | Mary Johnson | P200 | Pen | 10 | 2024-05-02 | Bob | West | No |
| 1003 | James Lee | P300 | Stapler | 3 | 2024-05-03 | Charlie | North | Yes |
| 1004 | Patricia Brown | P100 | Notebook | 7 | 2024-05-04 | Alice | East | No |
| 1005 | Michael Davis | P200 | Pen | 15 | 2024-05-05 | Bob | West | Yes |
| 1006 | Linda Wilson | P400 | Marker | 8 | 2024-05-06 | Charlie | South | No |
| 1007 | David Martinez | P300 | Stapler | 4 | 2024-05-07 | Alice | East | Yes |
| 1008 | Barbara Garcia | P100 | Notebook | 6 | 2024-05-08 | Bob | West | No |
Rename 'CustomerName' to 'Customer', 'ProductCode' to 'SKU', 'QuantitySold' to 'Quantity', 'SaleDate' to 'Date', 'SalesRep' to 'Sales Representative', 'DiscountApplied' to 'Discount'.Remove the 'SKU' column from the table.Drag and drop columns in Power Query Editor or use 'Choose Columns' to reorder as specified.Click 'Close & Apply' in Power Query Editor.--------------------------------------------- | Date | OrderID | Customer | ProductName | Quantity | Discount | Sales Representative | Region | |------------|---------|----------------|-------------|----------|----------|----------------------|--------| | 2024-05-01 | 1001 | John Smith | Notebook | 5 | Yes | Alice | East | | 2024-05-02 | 1002 | Mary Johnson | Pen | 10 | No | Bob | West | | 2024-05-03 | 1003 | James Lee | Stapler | 3 | Yes | Charlie | North | | 2024-05-04 | 1004 | Patricia Brown | Notebook | 7 | No | Alice | East | | 2024-05-05 | 1005 | Michael Davis | Pen | 15 | Yes | Bob | West | | 2024-05-06 | 1006 | Linda Wilson | Marker | 8 | No | Charlie | South | | 2024-05-07 | 1007 | David Martinez | Stapler | 4 | Yes | Alice | East | | 2024-05-08 | 1008 | Barbara Garcia | Notebook | 6 | No | Bob | West | ---------------------------------------------
Create a new calculated column in Power Query that combines 'Customer' and 'Region' into a single column called 'Customer Region'.
Practice
What is the main purpose of renaming columns in Power BI's Power Query Editor?
Solution
Step 1: Understand column renaming
Renaming columns means changing their names to something more descriptive or meaningful.Step 2: Purpose of renaming
This helps users and report viewers understand what data the column holds without confusion.Final Answer:
To give columns clear, meaningful names for easier understanding -> Option AQuick Check:
Renaming improves clarity = To give columns clear, meaningful names for easier understanding [OK]
- Confusing renaming with deleting columns
- Thinking renaming changes data values
- Mixing renaming with changing data types
Which of the following is the correct way to remove a column named SalesAmount in Power Query Editor?
Solution
Step 1: Identify how to remove columns in Power Query
Removing a column is done by right-clicking its header and choosing the remove option.Step 2: Check each option
Only Right-click theSalesAmountcolumn header and selectRemovecorrectly describes this action. Double-clicking edits names, renaming doesn't remove, and dragging reorders columns.Final Answer:
Right-click theSalesAmountcolumn header and selectRemove-> Option DQuick Check:
Remove column = Right-click + Remove [OK]
- Trying to delete by renaming
- Assuming double-click deletes column
- Dragging column removes it
Given a table with columns Product, Sales, and Date, what will be the new column order after applying this step in Power Query Editor?
Table.ReorderColumns(Source, {"Date", "Product", "Sales"})Solution
Step 1: Understand Table.ReorderColumns function
This function changes the order of columns to the list provided in the second argument.Step 2: Apply the given list
The list is ["Date", "Product", "Sales"], so the columns will be reordered exactly in that sequence.Final Answer:
["Date", "Product", "Sales"] -> Option CQuick Check:
ReorderColumns list = new order [OK]
- Assuming original order stays
- Mixing up column names order
- Ignoring the reorder list
You tried to rename a column in Power Query Editor but got an error. Which of these is the most likely cause?
Table.RenameColumns(Source, {"Sales", "Revenue"})Solution
Step 1: Check syntax for Table.RenameColumns
The function expects a list of pairs (old name, new name) inside another list, like {{"Old", "New"}}.Step 2: Identify error cause
The code uses a single pair without the outer list, causing a syntax error.Final Answer:
The rename list should be a list of lists like {{"Sales", "Revenue"}} -> Option BQuick Check:
RenameColumns needs list of lists [OK]
- Using single list instead of list of lists
- Thinking renaming is not allowed
- Expecting numeric names only
You have a table with columns ID, Name, Age, and Salary. You want to remove Age, rename Salary to Income, and reorder columns so Name comes first. Which sequence of Power Query steps is correct?
Solution
Step 1: Remove the
First, remove the unwantedAgecolumnAgecolumn to exclude it from the table.Step 2: Rename
Next, rename theSalarytoIncomeSalarycolumn toIncomefor clarity.Step 3: Reorder columns with
Finally, reorder columns soNamefirstNameis first, followed byIDandIncome.Final Answer:
RemoveAge, RenameSalarytoIncome, Reorder columns to ["Name", "ID", "Income"] -> Option AQuick Check:
Remove, Rename, Reorder in that order [OK]
- Reordering before removing columns
- Renaming wrong columns
- Removing needed columns by mistake
Ready to prove it?
Pass the test and this pattern moves unknown
