SUM and AVERAGE functions in Power BI - Real Business Scenario
| TransactionID | ProductCategory | SalesAmount | TransactionDate |
|---|---|---|---|
| 1001 | Electronics | 250 | 2024-01-15 |
| 1002 | Clothing | 80 | 2024-02-10 |
| 1003 | Electronics | 300 | 2024-03-05 |
| 1004 | Home | 150 | 2024-01-20 |
| 1005 | Clothing | 120 | 2024-03-15 |
| 1006 | Home | 200 | 2024-02-25 |
| 1007 | Electronics | 400 | 2024-03-28 |
| 1008 | Clothing | 60 | 2024-01-30 |
Use Power BI filter on TransactionDate column: TransactionDate >= DATE(2024,1,1) && TransactionDate <= DATE(2024,3,31)Total Sales = SUM('Sales'[SalesAmount])Average Sales = AVERAGE('Sales'[SalesAmount])Table visual configuration: Rows = ProductCategory, Values = Total Sales, Average SalesProductCategory | Total Sales | Average Sales ------------------------------------------- Electronics | 950 | 316.67 Clothing | 260 | 86.67 Home | 350 | 175.00
Create a line chart showing total sales trend by month for each product category in the last quarter.
Practice
What does the SUM function do in Power BI?
Solution
Step 1: Identify the purpose of SUM
The SUM function adds all numeric values in a specified column, unlike AVERAGE (mean), COUNT (rows), or MAX (highest).Final Answer:
Adds all numbers in a column -> Option AQuick Check:
SUM = total addition [OK]
- Confusing SUM with AVERAGE
- Thinking SUM counts rows
- Mixing SUM with MAX or MIN
Which of the following is the correct syntax to calculate the average of the Sales[Amount] column in DAX?
?Solution
Step 1: Recall correct DAX average syntax
In DAX, use AVERAGE(Sales[Amount]); AVG() and MEAN() do not exist, while SUM/COUNT works but is indirect.Final Answer:
AVERAGE(Sales[Amount]) -> Option BQuick Check:
AVERAGE() is the direct DAX function [OK]
- Using AVG() which is not a DAX function
- Trying MEAN() which doesn't exist in DAX
- Dividing SUM by COUNT manually instead of AVERAGE
Given the table Sales with Amount values: 100, 200, 300, what is the result of this DAX measure?
TotalAmount = SUM(Sales[Amount])
AverageAmount = AVERAGE(Sales[Amount])What are the values of TotalAmount and AverageAmount?
Solution
Step 1: Compute SUM and AVERAGE values
SUM(100 + 200 + 300) = 600; AVERAGE = 600 / 3 = 200.Final Answer:
TotalAmount = 600, AverageAmount = 200 -> Option AQuick Check:
SUM = 600, AVERAGE = 200 [OK]
- Mixing sum and average values
- Dividing sum by wrong count
- Confusing average with max or min
Identify the error in this DAX formula intended to calculate the average sales amount:
AverageSales = SUM(Sales[Amount]) / COUNT(Sales)Solution
Step 1: Locate COUNT syntax error
COUNT(Sales) is invalid as COUNT requires a column like Sales[Amount], not a table.Final Answer:
COUNT(Sales) should be COUNT(Sales[Amount]) -> Option DQuick Check:
COUNT needs a column, not a table [OK]
- Using COUNT with a table instead of a column
- Assuming SUM/COUNT division is invalid
- Replacing SUM with AVERAGE without reason
You have a Sales table with columns Region and Amount. You want to create a measure that shows the average sales amount only for the "East" region. Which DAX formula correctly calculates this?
?Solution
Step 1: Construct correct filtered average DAX
Use CALCULATE(AVERAGE(Sales[Amount]), Sales[Region] = "East") to apply filter context; others invalid (no WHERE, AVERAGE can't take table from FILTER directly, COUNT misused).Final Answer:
AverageEastSales = CALCULATE(AVERAGE(Sales[Amount]), Sales[Region] = "East") -> Option CQuick Check:
CALCULATE + filter = correct average [OK]
- Using WHERE clause which is invalid in DAX
- Trying to filter inside AVERAGE directly
- Dividing SUM by COUNT with filter incorrectly
Ready to prove it?
Pass the test and this pattern moves unknown
