Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
nestord
New Member

Specify custom date periods with predefined date periods.

HI All,

 

    I need to have posibility in the report to specify either predefined period(like last 7 days, last 30 days...) or custom date period(any possible date renge). And i have to compare measures for current and previous period. In order to compare two periods i added few tables(2 for current periods and two for previous ).

periodstables.png

 

For custom period selection just need to use slicer on date field and it works.  Periods i specified in DatePeriod and DatePeriod2 respectivly. But im not able to get it work together. Report should filter data based on custom date(date slicer), only in "Custom Date" is selected in DatePeriod filter. And vice verce if i change DatePeriod slicer it should ignor/or reset what is specified in Date slicer. 
periods.png

Is the any way to make it work together? 

Thanks in advance for any help!

 

1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee

@nestord

I'll use two measures(starting date and end date) and two tables(one lookup table and one calendar table). Then those two measures can be used to filter tables. Check more details in the attached pbix.

 

starting date = SWITCH(MAX('peroid lookup'[starting day]),DATE(1970,1,1),MIN('calendar'[Date]),MAX('peroid lookup'[starting day]))

end date = SWITCH(MAX('peroid lookup'[starting day]),DATE(1970,1,1),MAX('calendar'[Date]),TODAY())

####The calculated column in lookup table
starting day = 
SWITCH (
    TRUE (),
    'Peroid lookup'[Peroid] = "Last 07 days", TODAY () - 7,
    'Peroid lookup'[Peroid] = "Last 14 days", TODAY () - 14,
    'Peroid lookup'[Peroid] = "Last 30 days", TODAY () - 30,
    'Peroid lookup'[Peroid] = "Last 90 days", TODAY () - 90,
    'Peroid lookup'[Peroid] = "Today", TODAY (),
    DATE ( 1970, 1, 1 )
)

Capture.PNG

View solution in original post

4 REPLIES 4
Eric_Zhang
Microsoft Employee
Microsoft Employee

@nestord

I'll use two measures(starting date and end date) and two tables(one lookup table and one calendar table). Then those two measures can be used to filter tables. Check more details in the attached pbix.

 

starting date = SWITCH(MAX('peroid lookup'[starting day]),DATE(1970,1,1),MIN('calendar'[Date]),MAX('peroid lookup'[starting day]))

end date = SWITCH(MAX('peroid lookup'[starting day]),DATE(1970,1,1),MAX('calendar'[Date]),TODAY())

####The calculated column in lookup table
starting day = 
SWITCH (
    TRUE (),
    'Peroid lookup'[Peroid] = "Last 07 days", TODAY () - 7,
    'Peroid lookup'[Peroid] = "Last 14 days", TODAY () - 14,
    'Peroid lookup'[Peroid] = "Last 30 days", TODAY () - 30,
    'Peroid lookup'[Peroid] = "Last 90 days", TODAY () - 90,
    'Peroid lookup'[Peroid] = "Today", TODAY (),
    DATE ( 1970, 1, 1 )
)

Capture.PNG

This method works perfectly.The only glitch being when selecting something in the custom date range(second slicer) and then toggling the first time period selector.The selected date range filter gets stuck and doesnt blank out .Have you encountered a similar behaviour ?

@Eric_Zhang Thank you for your response. How you would suggest to calculate measure for those periods? Calculate masure for date range "starting date"\"end date"?


@nestord wrote:

@Eric_Zhang Thank you for your response. How you would suggest to calculate measure for those periods? Calculate masure for date range "starting date"\"end date"?


Yes, in the other measures' DAX fomular, filtter tables with those two measures.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors