Day 9: DAX — Intermediate Functions
5 questions · Power BI Interview Preparation
How does RANKX work in DAX?
RANKX(table, expression, [value], [order], [ties]) ranks rows in a table based on an expression. Example for ranking products by revenue: Product Rank = RANKX(ALL(Products), [Total Revenue], , DESC, DENSE) ALL(Products) creates the full list to rank against. [Total Revenue] is the measure to rank on. DESC means highest value = rank 1. DENSE means tied values get the same rank with no gaps (1,1,3) vs SKIP (1,1,3 with no rank 2). Used in visuals to show "Top 5 Products" or "Sales Rep Leaderboard".
What is HASONEVALUE and when do you use it?
HASONEVALUE(column) returns TRUE if the current filter context has exactly one value for that column — useful for showing a single value when a slicer has one item selected, or showing a message when multiple items are selected. Common use: dynamic titles: Report Title = IF(HASONEVALUE(Region[Region]), "Revenue Report — " & VALUES(Region[Region]), "Revenue Report — All Regions"). Another use: prevent meaningless calculations when too many values are selected for a measure to make sense.
What is SWITCH in DAX and how is it used?
SWITCH(expression, value1, result1, value2, result2, ..., [else]) is the DAX equivalent of a multi-branch IF or CASE statement. Much cleaner than nested IF for multiple conditions. Example: Quarter Label = SWITCH( QUARTER('Date Table'[Date]), 1, "Q1 (Jan-Mar)", 2, "Q2 (Apr-Jun)", 3, "Q3 (Jul-Sep)", 4, "Q4 (Oct-Dec)" ) SWITCH(TRUE(), ...) is used for range-based conditions: SWITCH(TRUE(), [Revenue] > 100000, "High", [Revenue] > 50000, "Medium", "Low").
How do you write a running total measure in DAX?
Running Total Revenue = CALCULATE( SUM(Sales[Revenue]), FILTER( ALL('Date Table'[Date]), 'Date Table'[Date] <= MAX('Date Table'[Date]) ) ) This returns the cumulative sum of revenue from the earliest date to the current date in context. MAX('Date Table'[Date]) gets the last date in the current filter context, and FILTER(...ALL...) includes all dates up to that point. Use in a line chart with Date on the axis to show cumulative growth over time.
What is SELECTEDVALUE in DAX?
SELECTEDVALUE(column, [alternate_result]) returns the value of a column when exactly one value is in the filter context, otherwise returns the alternate result. Cleaner than the IF(HASONEVALUE(col), VALUES(col), "Multiple") pattern. Common uses: dynamic measure titles that show the selected slicer item, capturing a user's selection to use in a calculation, building what-if parameters. Example: Selected Region = SELECTEDVALUE(Region[Region], "All Regions") Used in a card visual with a slicer — shows the currently selected region name or "All Regions" when nothing is selected.
Want live Power BI coaching?
Join EVIKA Academy for hands-on Power BI training with real projects and placement support in Delhi NCR.
Book Free Demo →