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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Help to filter Current week and next Week

I have dates column in a table.
How can i filter the current week
And next week.

Thanks in Advance..
Have a great day
1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Sorry for my late respond, we can adjust the formula as below.

Column = 
VAR next =
    TODAY () + 7
VAR yn =
    YEAR ( next )
VAR yt =
    YEAR ( TODAY () )
VAR weeknumt =
    WEEKNUM ( TODAY (),2 )
VAR weeknun =
    WEEKNUM ( next,2 )
VAR wek =
    WEEKNUM ( 'date'[Date],2 )
RETURN
    IF (
        OR (
            yn = YEAR ( 'date'[Date] )
                && weeknun = wek,
            yt = YEAR ( 'date'[Date] )
                && weeknumt = wek&& WEEKDAY('date'[Date],2)<=5
        ),
        "current week & next week",
        BLANK ()
    )

 

2.PNG

 

As the picture above, Sat and Sunday have been exculded for current week.

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

6 REPLIES 6
leletts
New Member

Hi, 

 

What if the next weeks are in the next year ? This formula doesn't seems to work correcly.. any help? 

Thanks! 

 

Formula I'm using : 

 

Date_Filter =
VAR next =
    TODAY () + 7
VAR yn =
    YEAR ( next )
VAR yt =
    YEAR ( TODAY () )
VAR weeknumt =
    WEEKNUM ( TODAY () )
VAR weeknun =
    WEEKNUM ( next )
VAR wek =
    WEEKNUM ( Dim_Calendar[Calendar Date] )
RETURN
    IF (
            yn = YEAR ( Dim_Calendar[Calendar Date] )
                && weeknun = wek ||
            yt = YEAR ( Dim_Calendar[Calendar Date] )
                && weeknumt = wek ||
            yt = YEAR ( Dim_Calendar[Calendar Date] )
                && WEEKNUM(TODAY() +14) = wek ||
            yt = YEAR ( Dim_Calendar[Calendar Date] )
                && WEEKNUM(TODAY() + 21) = wek ||
            yt = YEAR ( Dim_Calendar[Calendar Date] )
                && WEEKNUM(TODAY() +28)  = wek||
            yt = YEAR ( Dim_Calendar[Calendar Date] )
                && WEEKNUM(TODAY() +35)  = wek||
            yt = YEAR ( Dim_Calendar[Calendar Date] )
                && WEEKNUM(TODAY() +42)  = wek ,
        "current week & next weeks",
        BLANK ()
    )
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

I have created a sample for your reference, please check the pbix as attached.

Column = 
VAR next =
    TODAY () + 7
VAR yn =
    YEAR ( next )
VAR yt =
    YEAR ( TODAY () )
VAR weeknumt =
    WEEKNUM ( TODAY () )
VAR weeknun =
    WEEKNUM ( next )
VAR wek =
    WEEKNUM ( 'date'[Date] )
RETURN
    IF (
        OR (
            yn = YEAR ( 'date'[Date] )
                && weeknun = wek,
            yt = YEAR ( 'date'[Date] )
                && weeknumt = wek
        ),
        "current week & next week",
        BLANK ()
    )

Capture.PNG

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
amitchandak
Super User
Super User

First create a date table and join it with you fact

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

In your date table have week number.

You can create a formula lagging seven days and it should work

before 7 day = CALCULATE(sum(Sales[Sales Amount]),dateadd('Date'[date],-7,DAY)) 

 


Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Anonymous
Not applicable

@Anonymous Please create a calculated column as per below. If the week number is equivalent to current week number or week number one plus one then return true. you can use this column in filter.

Column = 
VAR _weeknum = WEEKNUM(TODAY())
RETURN IF(WEEKNUM('Table'[Date])=_weeknum||WEEKNUM('Table'[Date])= _weeknum+1,TRUE(),FALSE())

 

Anonymous
Not applicable

Thanks

 

Is there any option to filter only monday to friday in current week

i.e sunday and saturday to be excluded..

 

According to your query week is starting from sunday how to start from monday?

Hi @Anonymous ,

 

Sorry for my late respond, we can adjust the formula as below.

Column = 
VAR next =
    TODAY () + 7
VAR yn =
    YEAR ( next )
VAR yt =
    YEAR ( TODAY () )
VAR weeknumt =
    WEEKNUM ( TODAY (),2 )
VAR weeknun =
    WEEKNUM ( next,2 )
VAR wek =
    WEEKNUM ( 'date'[Date],2 )
RETURN
    IF (
        OR (
            yn = YEAR ( 'date'[Date] )
                && weeknun = wek,
            yt = YEAR ( 'date'[Date] )
                && weeknumt = wek&& WEEKDAY('date'[Date],2)<=5
        ),
        "current week & next week",
        BLANK ()
    )

 

2.PNG

 

As the picture above, Sat and Sunday have been exculded for current week.

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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