Guys, let's continue our Data Analyst Interview Series.
In this part, let's focus on Advanced DAX and practical Power BI scenarios. These questions will help you understand how to solve real business problems using DAX.
1️⃣ What is the difference between ALL, ALLSELECTED, and ALLEXCEPT?
Sample Answer:
These three DAX functions are used to modify filter context.
• ALL removes filters from the specified table or column.
• ALLSELECTED removes certain visual-level filters while retaining external selections, such as slicer selections.
• ALLEXCEPT removes filters from a table except for the specified columns.
Example:
Sales by Region % =
DIVIDE(
[Total Sales],
CALCULATE(
[Total Sales],
ALL(Region)
),
0
)This calculates each region's sales as a percentage of the total across all regions, while removing filters from the Region table.
2️⃣ What is the difference between RELATED and LOOKUPVALUE?
Sample Answer:
Both functions can retrieve values from another table, but they work differently.
RELATED retrieves a value from the one-side of an existing relationship when there is an appropriate row context.
Example:
Customer Country =
RELATED(Customers[Country])LOOKUPVALUE searches for a value based on specified matching conditions.
Example:
Customer Country =
LOOKUPVALUE(
Customers[Country],
Customers[CustomerID],
Sales[CustomerID]
)I prefer RELATED when a suitable relationship already exists. LOOKUPVALUE is useful when I need to search using specific matching conditions.
3️⃣ How do you calculate the rank of products based on sales?
Sample Answer:
I can use the RANKX function.
Product Rank =
RANKX(
ALL(Products[ProductName]),
[Total Sales],
,
DESC,
DENSE
)This ranks products from highest to lowest sales.
DENSE ranking means tied products receive the same rank, and the next rank is not skipped.
4️⃣ What is the difference between RANKX and TOPN?
Sample Answer:
RANKX assigns a ranking to records based on an expression.
TOPN returns a table containing the top N records based on a specified expression.
For example:
Top 5 Products =
TOPN(
5,
ALL(Products[ProductName]),
[Total Sales],
DESC
)I would use RANKX when I need to display rankings and TOPN when I need to identify a subset of top-performing records.
5️⃣ How do you calculate the average sales per customer?
Sample Answer:
First, I calculate total sales:
Total Sales =
SUM(Sales[SalesAmount])Then:
Average Sales per Customer =
DIVIDE(
[Total Sales],
DISTINCTCOUNT(Sales[CustomerID]),
0
)This calculates average sales per distinct customer appearing in the Sales table.
If the business requires average sales across all registered customers, including those with no purchases, I would use the Customers dimension table for the denominator instead.
6️⃣ How would you calculate the percentage contribution of each product category to total sales?
Sample Answer:
First, I create a Total Sales measure:
Total Sales =
SUM(Sales[SalesAmount])Then:
Category Contribution % =
DIVIDE(
[Total Sales],
CALCULATE(
[Total Sales],
REMOVEFILTERS(Products[Category])
),
0
)This calculates each category's contribution while removing the category filter.
Other report filters, such as date or region, remain applicable.
7️⃣ What is the difference between ISBLANK and COALESCE?
Sample Answer:
ISBLANK checks whether an expression returns a blank value.
Example: