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
game1
Helper III
Helper III

Filter with the CALENDAR (range slicer) and with the options “last 7 days” and “last 60 days

Hello, 

I have Table1[dateExam] and Table1[numberPeople].

First, I need to use a CALENDAR (range slicer) to select a date (it must only consider the max date of range slicer selected). For example, I can select 10/01/2021 as my maximum date.

Second, I need to check one of the options: (in Segment). For example, I can check the option “last 7 days”.

Then, it would return me the numberPeople for the “last 7 days” of the selected date in the CALENDAR.(So the “last 7 days” is base on the CALENDAR (range slicer) I have selected.)

In other words, it would return me in a graphic, the numberPeople between 03/01/2021 and 10/01/2021.

For this example, in a graphic, I would have for each day between 03/01/2021 and 10/01/2021, the numberPeople that have done dateExam from Table1[dateExam].

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @game1 ,

 

You can try formula like below:

NumberPeopleLastDays_slicer =
VAR MaxSelectedDate =
    MAX ( 'Calendar'[Date] )
VAR MinSelectedDate =
    MaxSelectedDate
        - CALCULATE (
            MAX ( slicer[Value] ),
            FILTER ( slicer, slicer[last_] = SELECTEDVALUE ( slicer[last_] ) )
        )
RETURN
    CALCULATE (
        SUM ( Table1[numberPeople] ),
        FILTER (
            Table1,
            Table1[dateExam] >= MinSelectedDate
                && Table1[dateExam] <= MaxSelectedDate
        )
    )

create slicer table and calendar table:

vkongfanfmsft_0-1706258693404.png

vkongfanfmsft_1-1706258718089.png

vkongfanfmsft_2-1706258751240.png

vkongfanfmsft_3-1706258767672.png

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @game1 ,

 

You can try formula like below:

NumberPeopleLastDays_slicer =
VAR MaxSelectedDate =
    MAX ( 'Calendar'[Date] )
VAR MinSelectedDate =
    MaxSelectedDate
        - CALCULATE (
            MAX ( slicer[Value] ),
            FILTER ( slicer, slicer[last_] = SELECTEDVALUE ( slicer[last_] ) )
        )
RETURN
    CALCULATE (
        SUM ( Table1[numberPeople] ),
        FILTER (
            Table1,
            Table1[dateExam] >= MinSelectedDate
                && Table1[dateExam] <= MaxSelectedDate
        )
    )

create slicer table and calendar table:

vkongfanfmsft_0-1706258693404.png

vkongfanfmsft_1-1706258718089.png

vkongfanfmsft_2-1706258751240.png

vkongfanfmsft_3-1706258767672.png

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

Fowmy
Super User
Super User

@game1 

To calculate for any time period based on the current date selection, follow the following pattern. you can chagne the Day to Month, Quarter ans so on,

Last 7 Days = CALCULATE( [Sales Amount] , DATESINPERIOD( 'Date'[Date] , MAX( 'Date'[Date] ) , -7 , DAY ) )

. In this example, the sales amount is calculated for the past 7 days from the current date selection. It takes the max of the current range.

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

No! It is not working. I can select 2 options last 7 days or last 60 days and I need also the calendar (range slicer).

@game1 

Sharing a dummy Power BI file representing your scenario would be beneficial. You can save the Power BI file on Google Drive or any other cloud storage platform and provide the link here. Kindly ensure that permission is granted to open the file.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Capture d’écran, le 2024-01-14 à 03.04.23.pngCapture d’écran, le 2024-01-14 à 03.04.46.png

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.