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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Nathan___Mox
Regular Visitor

create new column with current week/date filter

Hey all,

 

I'm trying to create a new column filtered by the current/todays date/week, see below

itemweek startingamountnew column
a30 april 2023100150
a7 may 2023 (current)150150
a14 may 202350150
a21 may 2023200150
b30 april 2023300500
b7 may 2023500500
b14 may 2023200500
b21 may 202350500

 

could i please get some help on this, if you need any more information let me know.

 

Thanks

Nathan

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1683600992079.png

 

Expected result CC =
VAR _year = 2023
VAR _calendar =
    ADDCOLUMNS (
        CALENDAR ( DATE ( _year - 1, 1, 1 ), DATE ( _year + 1, 12, 31 ) ),
        "@wknum", WEEKNUM ( [Date] + 1, 21 )
    )
VAR _calendartable =
    ADDCOLUMNS (
        _calendar,
        "@year",
            IF (
                MONTH ( [Date] ) = 1
                    && [@wknum] > 50,
                YEAR ( [Date] ) - 1,
                YEAR ( [Date] )
            )
    )
VAR _todaywk =
    MINX ( FILTER ( _calendartable, [Date] = TODAY () ), [@wknum] )
VAR _todayyear =
    MINX ( FILTER ( _calendartable, [Date] = TODAY () ), [@year] )
VAR _wkyearstartingdate =
    MINX (
        FILTER ( _calendartable, [@wknum] = _todaywk && [@year] = _todayyear ),
        [Date]
    )
RETURN
    SUMX (
        FILTER (
            Data,
            Data[item] = EARLIER ( Data[item] )
                && Data[week starting] = _wkyearstartingdate
        ),
        Data[amount]
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1683600992079.png

 

Expected result CC =
VAR _year = 2023
VAR _calendar =
    ADDCOLUMNS (
        CALENDAR ( DATE ( _year - 1, 1, 1 ), DATE ( _year + 1, 12, 31 ) ),
        "@wknum", WEEKNUM ( [Date] + 1, 21 )
    )
VAR _calendartable =
    ADDCOLUMNS (
        _calendar,
        "@year",
            IF (
                MONTH ( [Date] ) = 1
                    && [@wknum] > 50,
                YEAR ( [Date] ) - 1,
                YEAR ( [Date] )
            )
    )
VAR _todaywk =
    MINX ( FILTER ( _calendartable, [Date] = TODAY () ), [@wknum] )
VAR _todayyear =
    MINX ( FILTER ( _calendartable, [Date] = TODAY () ), [@year] )
VAR _wkyearstartingdate =
    MINX (
        FILTER ( _calendartable, [@wknum] = _todaywk && [@year] = _todayyear ),
        [Date]
    )
RETURN
    SUMX (
        FILTER (
            Data,
            Data[item] = EARLIER ( Data[item] )
                && Data[week starting] = _wkyearstartingdate
        ),
        Data[amount]
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

This works thank you heaps!! 

 

Just one question the first line 'Var _year = 2023' does this mean that only dates in 2023 will work for the dax calculation?

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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