You are developing a Power BI report that tracks daily inventory levels. The data model contains an 'Inventory' table with 'ProductKey', 'TransactionDate', and 'UnitsInStock' columns. You also have a 'Date' table that is correctly marked as a date table. You need to create a measure that calculates the closing inventory balance. The measure must show the stock level from the last date within any selected time period (e.g., month, quarter, or year), rather than a sum of the stock levels throughout the period. Which DAX formula correctly calculates this semi-additive measure?
The correct DAX formula is CALCULATE(SUM('Inventory'[UnitsInStock]), LASTDATE('Date'[Date])). Here's why:
Correct Answer: This formula uses the CALCULATE function to modify the filter context. The LASTDATE('Date'[Date]) function returns a table containing only the last date in the current filter context (e.g., the last day of a selected month). CALCULATE then applies this new single-day filter context to the SUM('Inventory'[UnitsInStock]) expression, effectively calculating the stock for only the last day of the period. This is the standard pattern for handling semi-additive measures like inventory balances.
SUM('Inventory'[UnitsInStock]): This is incorrect because it is a fully additive measure. It would sum the 'UnitsInStock' for every day in the selected period, leading to a vastly inflated and incorrect number. For example, the inventory for a month would be the sum of 30 daily balances instead of the balance on the last day.
AVERAGEX(VALUES('Date'[Date]), SUM('Inventory'[UnitsInStock])): This is incorrect because it calculates the average daily stock over the period, not the closing balance on the last day. While this might be a useful metric in some scenarios, it does not meet the requirement for a closing balance.
TOTALYTD(SUM('Inventory'[UnitsInStock]), 'Date'[Date]): This is incorrect as it is a time intelligence function that calculates the cumulative (year-to-date) total. It does not isolate the value from the last day of the period; instead, it sums all values from the start of the year up to the end of the current period.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the CALCULATE function in DAX?
Open an interactive chat with Bash
What does the LASTDATE function do in DAX?
Open an interactive chat with Bash
Why is SUM('Inventory'[UnitsInStock]) not correct for calculating closing inventory?
Open an interactive chat with Bash
Microsoft Power BI Data Analyst
Model the Data
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .