Advanced DAX: Variables, Ranking, Virtual Tables and Totals
Understand it in simple language
Variables give intermediate results a name and can avoid repeated work. FILTER returns a table subset. VALUES returns distinct visible values. SELECTEDVALUE returns a single value or an alternate result. RANKX evaluates an expression across a table. Virtual tables exist during evaluation rather than as stored model tables.
A grand total re-evaluates a measure in total context; it does not always add the displayed cells. This is correct for a ratio such as margin. Use an iterator only when adding per-group results is actually the requirement.
Do it step by step
Create:
Product Rank = RANKX(ALL(Products[ProductName]), [Revenue], , DESC, DENSE)
High Value Revenue = SUMX(FILTER(Sales, Sales[Quantity] * Sales[UnitPrice] >= 500), Sales[Quantity] * Sales[UnitPrice])
Margin Label = VAR M = [Margin] RETURN IF(ISBLANK(M), "No sales", IF(M >= 0.4, "On target", "Review"))
Product rank puts Laptop before Mouse; High Value Revenue is 2000 (500 + 750 + 750). Test the measures with no filters, each region and each product.
Check your result
When might ALLSELECTED be appropriate for ranking? When the comparison set should retain outer selections; test the actual visual context.
If something goes wrong
Do not patch totals with SUMX without first explaining the required total to the metric owner.
Practice data and learning method
Industry practice collection: downloadable retail, finance, HR and operations datasets, dictionaries, full walkthroughs and answer sheets. The cases contain multiple years, multiple related tables, deliberate data defects and known-answer checks. Progress from the small foundation files below to these cases; do not reuse the foundation totals for the larger datasets.
Download Sales.csv, Products.csv, and the dataset guide. These files contain synthetic training data, not real customers. Use the Power BI virtual labs for guided browser practice. Each lab states its supported operations. Then repeat the procedure above in the actual Microsoft tools and save evidence of your result. Try another filter or an intentionally incorrect setting and explain what changed before moving on.
Guided practicals for this topic
Virtual lab · Microsoft Power BI · 35 min
Rank and inspect the top five products
Hands-on retail case: load the downloadable CSV tables, perform the actions, inspect the full-data result and reconcile it. Includes a paired Desktop procedure.
Continue learning from Microsoft
Power BI documentation · DAX reference · Power Query M reference · Power BI analyst skills map. Features, licensing, menus and availability can change; check the relevant official page for your environment.
Practise this topic
Hands-on virtual lab
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.