# DATESINPERIOD

## Syntax of the DATESINPERIOD function

The syntax of the DATESINPERIOD function is as follows:

DATESINPERIOD(❰dates❱,❰startdate❱,❰numb_intervals❱,❰interval❱)

``` Here are the arguments used in the syntax: **dates:** This is a column that contains the dates that you want to filter. **startdate:** This is the start date of the period you want to filter. **numb_intervals:** This is the number of intervals you want to filter. **interval:** This specifies the interval that you want to filter. The options are year, quarter, month, week, or day. Example of using the DATESINPERIOD function Suppose we have a table of sales data that includes a column for the sale date. We want to calculate the total sales for the last three months. We can use the DATESINPERIOD function as follows: ```

Total Sales Last Three Months = CALCULATE(SUM(Sales[Amount]),DATESINPERIOD(Sales[Date],LASTDATE(Sales[Date]),-3,MONTH))

``` Here, we are using the CALCULATE function to aggregate the sales amount. We then use the DATESINPERIOD function to filter the sales data based on the last three months. We are using the LASTDATE function to get the last date in the sales date column. Using the DATESINPERIOD function with other functions The DATESINPERIOD function can also be used in conjunction with other functions to provide more advanced filtering capabilities. For example, we can use the function with the FILTER function to filter data based on specific criteria. Suppose we have a table of sales data that includes columns for the sale date, product, and sales amount. We want to calculate the total sales for the last three months for a specific product. We can use the following formula: ```

Total Sales Last Three Months for Product A = CALCULATE(SUM(Sales[Amount]),FILTER(Sales,Sales[Product]=”Product A”),DATESINPERIOD(Sales[Date],LASTDATE(Sales[Date]),-3,MONTH))

``` Here, we are using the FILTER function to filter the sales data for the product "Product A". We are then using the DATESINPERIOD function to filter the data based on the last three months. The DATESINPERIOD function is an essential function in Power BI that enables the filtering of data based on specific time periods. By using this function, you can easily filter data based on months, quarters, years, weeks, or days. It is an excellent tool for business analysts, data analysts, and data scientists who want to analyze data based on specific time periods. Power BI DAX Training Courses by G Com Solutions (0800 998 9248) Power BI DAX Intensive Training Course £1,260.00 – £31,860.00 Select optionsContinue Loading Done Power BI DAX Introduction £474.00 – £11,700.00 Select optionsContinue Loading Done Power BI DAX Intermediate £474.00 – £11,700.00 Select optionsContinue Loading Done Power BI DAX Advanced £474.00 – £11,700.00 Select optionsContinue Loading Done Upcoming Courses Contact Us Subject Your Name (required) Company/Organisation Email (required) Telephone Training Course(s) Power BI Intensive TrainingPower BI introduction Power BI IntermediatePower BI AdvancedDAXPower Query MPower BI CertificationPower BI AdministrationPower PlatformPower AutomatePower AppsOTHER Your Message Upload Example Document(s) (Zip multiple files) ```
``` ```
``` ```
``` ```
``` ```
``` ```