Power BI Interview Questions
Provide a measure that gives the Running/cumulative total using the date table
The Sales table had its date column linked to the Date table. The Date table was marked as the primary date table. In the Sales table is a measure named Net = (SUM(Sales[Net Sales])).
This measure calculates cumulative sales to date, including all dates, even when not filtered in the current context. It is defined by using the CALCULATE function along with the FILTER and ALL functions.
CALCULATE([Net],…) is used for computing Net Sales.
FILTER(ALL(‘Date’), ‘Date’[Date] <= MAX(‘Date’[Date])) will filter the Date table for all dates where the date is less than or equal to the maximum date in the current context.
Measure 2: Cumulative Sales using the Filter Function (Selected Dates)
This measure calculates cumulative sales of selected dates. It uses in its definition both the CALCULATE function and also the FILTER and ALLSELECTED functions to constrain the calculation to just the selected dates.
CALCULATE([Net], …) computes the Net Sales.
FILTER(ALLSELECTED(‘Date’[Date]), …) filters the Date table to include only the selected dates (ALLSELECTED(‘Date’[Date])), where the date is less than or equal to the maximum date (MAX(‘Date’[Date])) in the filter context.
Measure 3: Cumulative Sales using a Window Function (All Dates)
This measure computes cumulative sales by window function for all dates. It is defined over a function that takes CALCULATE and the window function.
CALCULATE([Net], …) is used to calculate the Net Sales.
Window(…) is defining the window function, running from the absolute first position to the relative zero position over all dates in the Date table, ordered in ascending order.
Measure 4: Cumulative Sales using a Window Function (Selected Dates)
This measure calculates cumulative sales by using a window function considering only the selected dates. The measure is defined by combining functions CALCULATE and window function, using ALLSELECTED to focus on selected dates.
CALCULATE([Net], …) calculates the Net Sales.
Window(…) defines the window function, which operates from the absolute first position to the relative zero position, over all selected dates in the Date table, ordered in ascending order.
These measures enable you to calculate cumulative sales or running totals in Power BI, based on your specific needs—whether considering all dates or only selected dates—using either filter functions or window functions.
Add comment