Forum Discussion

Nathan___Mox's avatar
Nathan___Mox
Regular Visitor
3 years ago
Solved

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 item week starting amount new column a 30 april 2023 100 150 a 7 may 2023 (current)...
  • Jihwan_Kim's avatar
    3 years ago

    Hi,

    Please check the below picture and the attached pbix file.

     

     

    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]
        )