Syntax of PREVIOUSDAY Function
The syntax of the PREVIOUSDAY function is simple. It takes a column as an argument and returns the value of the column from the previous day. Here is the syntax of the function:
In this syntax, `❰column❱` is the name of the column that you want to retrieve the previous day’s data from.
Example of Using PREVIOUSDAY Function
Let’s take a look at an example of how to use the PREVIOUSDAY function in Power BI DAX. Suppose we have a table called “Sales” that contains the sales data for a particular product. The table has the following columns: “Date”, “Product”, and “Sales Amount”.
To retrieve the sales amount for the previous day, we can use the following formula:
Previous Day Sales Amount = CALCULATE(SUM(Sales[Sales Amount]), PREVIOUSDAY(Sales[Date]))
In this formula, the CALCULATE function is used to calculate the sum of the “Sales Amount” column for the previous day. The PREVIOUSDAY function is used to retrieve the data for the previous day from the “Date” column.
Using PREVIOUSDAY in Time Intelligence Functions
The PREVIOUSDAY function can be used in a variety of time intelligence functions in Power BI DAX. These functions allow you to perform calculations and analysis based on time periods, such as days, weeks, months, quarters, and years.
For example, you can use the PREVIOUSDAY function in the TOTALYTD function to calculate the total sales for the current year up to the previous day:
Total Sales YTD - Previous Day = TOTALYTD(SUM(Sales[Sales Amount]),Sales[Date],FILTER(ALL(Sales),Sales[Date]❰=PREVIOUSDAY(Sales[Date])))
In this formula, the TOTALYTD function is used to calculate the total sales for the current year up to the previous day. The FILTER function is used to filter the data based on the date column. The ALL function is used to remove any filters that may have been applied to the data.
The PREVIOUSDAY function in Power BI DAX is a useful tool for retrieving data from the previous day. It can be used in a variety of time intelligence functions to perform calculations and analysis based on time periods. By using the examples and syntax provided in this article, you can start using the PREVIOUSDAY function in your own Power BI DAX formulas and analysis.
Power BI DAX Training Courses by G Com Solutions (0800 998 9248)
Power BI DAX Intensive Training Course£1,050.00 – £26,550.00
Power BI DAX Introduction£395.00 – £9,750.00
Power BI DAX Intermediate£395.00 – £9,750.00
Power BI DAX Advanced£395.00 – £9,750.00