Dax Function: PREVIOUSDAY
Category: Time Intelligence Functions
The PREVIOUSDAY
function in Power BI is a time intelligence DAX function that returns a table containing all the dates for the previous day based on the current context. It is primarily used to filter data for calculating metrics specific to the day before the current one.
Purpose of the Function
The function facilitates day-over-day comparisons, enabling users to:
- Analyze performance metrics for the day immediately preceding the current day.
- Perform calculations for daily trends, such as changes in revenue or number of transactions.
Type of Calculations
- Day-over-day performance tracking.
- Filtering data to show values exclusively for the previous day.
- Supporting custom calculations involving past day data.
Practical Use Cases
- Daily Sales Analysis: Compare today’s sales with the sales from the previous day.
- Operational Metrics: Monitor daily fluctuations in inventory levels or ticket resolution counts.
- Error Tracking: Analyze anomalies or trends based on past-day logs.
PREVIOUSDAY()
Parameter | Type | Description |
---|---|---|
dates | Column | A column containing date values, typically from a date table in your model. |
How Does PREVIOUSDAY Dax Function Works?
- Input Date Column: The function uses a date column to define the current time context.
- Calculate Previous Day: It shifts the date range back by one day.
- Apply Filter Context: The resulting table of dates is applied as a filter to evaluate measures or create visualizations.
For instance, in a report filtered to “March 5, 2025,” PREVIOUSDAY
would return “March 4, 2025.”
What Does It Return?
The function returns a table of dates corresponding to the previous day in the current filter context. The returned table can then be used in calculations or filters.
When Should We Use It?
- When tracking daily trends or changes in metrics.
- For generating reports with comparisons between the current and previous day.
- In dashboards requiring day-over-day performance insights.
Examples
Basic Usage
Sales Previous Day = CALCULATE(
SUM(Sales[Amount]),
PREVIOUSDAY(Dates[Date])
)
Calculates the total sales for the previous day.
Column Usage:
Active Users Previous Day = CALCULATE(
COUNT(Users[UserID]),
PREVIOUSDAY(Dates[Date])
)
Counts the number of active users from the previous day.
Advanced Usage
Day-over-Day Growth = DIVIDE(
SUM(Sales[Amount]) - CALCULATE(SUM(Sales[Amount]), PREVIOUSDAY(Dates[Date])),
CALCULATE(SUM(Sales[Amount]), PREVIOUSDAY(Dates[Date]))
)
Calculates day-over-day sales growth percentage.
Tips and Tricks
- Date Table Usage: Ensure you have a complete and continuous date table to avoid gaps in calculations.
- Combining with Other Functions: Pair with
NEXTDAY
,TODAY
, or custom measures for more dynamic analyses. - Avoiding Time Zones Issues: Be cautious with date values that include time zones, as they might affect the function’s output.
Potential Pitfalls:
- Missing dates in the
dates
column can lead to incorrect or incomplete results. - Using the function without a proper date table may lead to unexpected behavior.
Performance Impact of PREVIOUSDAY DAX Function:
- Optimized for use with well-structured date tables and indexed datasets.
- Avoid overcomplicating queries by nesting within multiple filters.
Related Functions You Might Need
NEXTDAY
: Returns the dates for the day after the current context.DATEADD
: Provides more flexibility to add or subtract custom time periods.SAMEPERIODLASTYEAR
: Returns the same period in the previous year.PARALLELPERIOD
: Shifts a time period forward or backward by specified intervals.
Want to Learn More?
For more information, check out the official Microsoft documentation for PREVIOUSDAY. You can also experiment with this function in your Power BI reports to explore its capabilities.
Unlock the full capabilities of Power BI and elevate your data insights with our specialized consulting services. Whether you need guidance on advanced DAX functions like those highlighted here, support in designing interactive dashboards, or expertise in optimizing data models for enhanced performance, our experienced Power BI consultants are equipped to deliver customized solutions for your business. Explore our Power BI Consulting Services page to discover how we can help your organization make smarter, data-driven decisions.
It returns a table of dates for the day immediately preceding the current filter context.
While possible, it is not recommended. A properly configured date table ensures accurate results.
PREVIOUSDAY
only shifts back by one day, whereas DATEADD
allows for flexible time shifts by any number of days, months, or years.
Yes, as long as the date table aligns with the custom fiscal calendar.
Missing dates in the column may lead to gaps in the returned data or errors in calculations.
Established in 2020, Lets Viz Technologies provides a full range of high-quality data analysis and data visualization services. We are also an authorized Zoho Partner.
Sitelinks