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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
sonya7
Helper III
Helper III

Calendar week range

Hello everyone,

I have a periodic table of dates that I want to use as follows. I am using this on slicer. but I want to calculate the last 1 and 2 weeks as calendar week like in powerbi. how can I do that? Last 1 week date range for today I want: 27.11.2022-3.11.2022

 


VAR _datetable = DimTarih
VAR _today = TODAY()
VAR _year = YEAR(TODAY())
VAR _thisyearstart = DATE(_year,1,1)
VAR _year1 = YEAR(TODAY())-1
VAR _yearstart = DATE(_year1,1,1)
VAR _month = MONTH(TODAY())
VAR _thismonthstart = DATE(_year,_month,1)
VAR _thisyearstart1 = DATE(_year,12,31)

RETURN UNION(
ADDCOLUMNS(FILTER(_datetable,[TheDate]>_today-7 && [TheDate]<=_today),"Period","Last 1 week","Order",1),
ADDCOLUMNS(FILTER(_datetable,[TheDate]>_today-14 && [TheDate]<=_today),"Period","last 2 week","Order",2)

)

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @sonya7 

You need to subtract the value of WEEKDAY(_today) in your original formula.

t1 = 
VAR _datetable = DimTarih
VAR _today =
    TODAY ()
VAR _year =
    YEAR ( TODAY () )
VAR _thisyearstart =
    DATE ( _year, 1, 1 )
VAR _year1 =
    YEAR ( TODAY () ) - 1
VAR _yearstart =
    DATE ( _year1, 1, 1 )
VAR _month =
    MONTH ( TODAY () )
VAR _thismonthstart =
    DATE ( _year, _month, 1 )
VAR _thisyearstart1 =
    DATE ( _year, 12, 31 )
RETURN
    UNION (
        ADDCOLUMNS (
            FILTER (
                _datetable,
                [TheDate]
                    > _today - 7
                        - WEEKDAY ( _today )
                    && [TheDate]
                        <= _today - WEEKDAY ( _today )
            ),
            "Period", "Last 1 week",
            "Order", 1
        ),
        ADDCOLUMNS (
            FILTER (
                _datetable,
                [TheDate]
                    > _today - 14
                        - WEEKDAY ( _today )
                    && [TheDate]
                        <= _today - WEEKDAY ( _today ) - 7
            ),
            "Period", "last 2 week",
            "Order", 2
        )
    )

Result:

veasonfmsft_0-1670410332575.png

Best Regards,
Community Support Team _ Eason
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

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @sonya7 

You need to subtract the value of WEEKDAY(_today) in your original formula.

t1 = 
VAR _datetable = DimTarih
VAR _today =
    TODAY ()
VAR _year =
    YEAR ( TODAY () )
VAR _thisyearstart =
    DATE ( _year, 1, 1 )
VAR _year1 =
    YEAR ( TODAY () ) - 1
VAR _yearstart =
    DATE ( _year1, 1, 1 )
VAR _month =
    MONTH ( TODAY () )
VAR _thismonthstart =
    DATE ( _year, _month, 1 )
VAR _thisyearstart1 =
    DATE ( _year, 12, 31 )
RETURN
    UNION (
        ADDCOLUMNS (
            FILTER (
                _datetable,
                [TheDate]
                    > _today - 7
                        - WEEKDAY ( _today )
                    && [TheDate]
                        <= _today - WEEKDAY ( _today )
            ),
            "Period", "Last 1 week",
            "Order", 1
        ),
        ADDCOLUMNS (
            FILTER (
                _datetable,
                [TheDate]
                    > _today - 14
                        - WEEKDAY ( _today )
                    && [TheDate]
                        <= _today - WEEKDAY ( _today ) - 7
            ),
            "Period", "last 2 week",
            "Order", 2
        )
    )

Result:

veasonfmsft_0-1670410332575.png

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

You are legend! thank you

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors