How to Show Previous Value by Date WITHOUT Date Being Used in the Visual - Power BI DAX Tutorial
Power BI offers robust capabilities for analyzing data, but certain scenarios—like retrieving previous values based on dates without using the date column in visuals—can pose challenges. In this tutorial, Nick Lee demonstrates how to solve this advanced problem using DAX and virtual tables. By leveraging calculated measures, Power BI users can dynamically analyze data without displaying dates in their visuals.
Problem Overview
The goal is to display the latest, second latest, and even third latest sales prices for products in a table, but without directly incorporating dates into the visual. This solution must remain dynamic, adapting to slicers or filters applied to the dataset.
Step-by-Step Solution
1. Create a Measure for the Latest Sale Price
- Use the
CALCULATEfunction to modify the filter context. - Filter by the maximum order date for the product to get the most recent sale price.
2. Build a Virtual Ranking System
- To handle second and third latest sales, create a ranking system using the
RANKXfunction. - Start by creating a static calculated column for validation, ranking the order dates by product in descending order.
- Validate the ranking logic by checking the data in the table view.
3. Transition to Virtual Tables
- Replace the static ranking column with a dynamic virtual table using
ADDCOLUMNSandRANKXin a measure. - Filter the virtual table to isolate the desired rank, such as the second or third latest sale price.
4. Advanced Scenarios
- Calculate rolling sums, such as the sum of the latest three sales, by adjusting the filter to include multiple ranks.
- Extend the solution to other scenarios without disrupting the visual layout.
Advantages of This Solution
- Dynamic Adaptation: The measures automatically respond to slicers and filters, ensuring flexibility.
- No Dependency on Dates in Visuals: Users can focus on key metrics without cluttering visuals with dates.
- Scalability: Extendable to multiple scenarios, such as calculating averages or comparing historical data.
Conclusion
Nick’s solution showcases the power of DAX in addressing complex business scenarios in Power BI. By incorporating virtual tables and dynamic calculations, users can craft advanced analytics without compromising visual clarity. Whether you're exploring sales trends or analyzing historical metrics, these techniques can significantly enhance your Power BI reports.
Don't forget to check out the Pragmatic Works' on-demand learning platform for more insightful content and training sessions on DAX, Power BI and other Microsoft applications. Be sure to subscribe to the Pragmatic Works YouTube channel to stay up-to-date on the latest tips and tricks.
Sign-up now and get instant access
ABOUT THE AUTHOR
Nick has been a dedicated trainer and consultant since 2018, leveraging his extensive experience working with major companies, including Fortune 200 corporations, professional sports organizations, government entities, and leading firms in the finance and healthcare sectors. With a specialized focus on Power BI and data engineering, Nick has consistently demonstrated his ability to drive data-driven decision-making and optimize business processes. His commitment to excellence and his in-depth technical expertise have made him a trusted advisor and sought-after expert in the industry.
Free Community Plan
On-demand learning
Most Recent
private training

Leave a comment