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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Jan_Cools
Regular Visitor

How to determine the "same" date in the month last year based on working days remaining

Hello,

 

first post in this forum!

 

I'm struggling to get a workaround the following issue:

I've created some visuals where I can follow the day to day cumulative (month to date) sales for a specific month.

Based on a slicer, I select a certain date in the month and would like to compare the month to date sales value with the same month last year, but the related date, last year, should be the one that has the same amount of working days left as the date I selected in the filter.

 

I used the function NETWORKINGDAYS to determine how many working days are left in the month for which I picked the date, but how to get the relevant date in the month of previous year.

For the ease of understanding, assume that only Saturday and Sundays are non working days.

Any help is welcome!

 

The formula used to determine the working days left based on selection is:

Remaining_Work_Days = NETWORKDAYS(SELECTEDVALUE('CALENDAR'[Date]),ENDOFMONTH('CALENDAR'[Date]),1)
 
Calendar table is in place and all relevant relationships, with the sales table, are made.

 

Thanks, Jan

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @Jan_Cools 

 

May I ask if this is the expected output you are looking for? Based on your description, I have created many measures to achieve the effect you are looking for. Following picture shows the effect of the display.

vyaningymsft_2-1703577386476.png

Measures:

 

Remaining_Work_Days =

VAR remaining_Work_Days =

    NETWORKDAYS ( SELECTEDVALUE ( 'Table'[Date] ), ENDOFMONTH ( 'Table'[Date] ), 1 )

RETURN

    remaining_Work_Days



SameWorkingDayLastYear =

VAR SelectedDate =

    SELECTEDVALUE ( 'Table'[Date] )

VAR SameDayLastYear =

    SAMEPERIODLASTYEAR ( 'Table'[Date] )

VAR SameMonthLastYear =

    EOMONTH ( SelectedDate, -12 )

VAR WorkingDaysLastYear =

    NETWORKDAYS ( SameDayLastYear, SameMonthLastYear )

RETURN

    WorkingDaysLastYear



TrueValuesLastYear =

VAR DIFFDAYS = [Remaining_Work_Days] - [SameWorkingDayLastYear]

VAR SelectedDate =

    SELECTEDVALUE ( 'Table'[Date] )

VAR SameDayLastYear =

    SAMEPERIODLASTYEAR ( 'Table'[Date] )

VAR StartMonthLastYear =

    EOMONTH ( SelectedDate, -13 ) + 1

VAR _tureSameDayLastYear =

    SWITCH (

        DIFFDAYS,

        -1,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear + 1 ) = 7, SameDayLastYear + 3,

                WEEKDAY ( SameDayLastYear + 1 ) = 1, SameDayLastYear + 2,

                SameDayLastYear + 1

            ),

        -2,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear + 2 ) = 7, SameDayLastYear + 4,

                WEEKDAY ( SameDayLastYear + 2 ) = 1, SameDayLastYear + 3,

                SameDayLastYear + 2

            ),

        -3,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear + 3 ) = 7, SameDayLastYear + 5,

                WEEKDAY ( SameDayLastYear + 3 ) = 1, SameDayLastYear + 4,

                SameDayLastYear + 3

            ),

        1,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear - 1 ) = 7, SameDayLastYear - 2,

                WEEKDAY ( SameDayLastYear - 1 ) = 1, SameDayLastYear - 3,

                SameDayLastYear - 1

            ),

        2,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear - 2 ) = 7, SameDayLastYear - 4,

                WEEKDAY ( SameDayLastYear - 2 ) = 1, SameDayLastYear - 3,

                SameDayLastYear - 2

            ),

        3,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear - 3 ) = 7, SameDayLastYear - 5,

                WEEKDAY ( SameDayLastYear - 3 ) = 1, SameDayLastYear - 4,

                SameDayLastYear - 3

            ),

        SameDayLastYear

    )

VAR _ValuesLastYear =

    CALCULATE (

        SUM ( 'CALENDAR'[Value] ),

        'CALENDAR'[Date] >= StartMonthLastYear

            && 'CALENDAR'[Date] <= _tureSameDayLastYear

    )

RETURN

    _ValuesLastYear



ValuesThisYear =

VAR SelectedDate =

    SELECTEDVALUE ( 'Table'[Date] )

VAR DateStartOfMonth =

    EOMONTH ( SelectedDate, -1 ) + 1

VAR _ValuesThisYear =

    CALCULATE (

        SUM ( 'CALENDAR'[Value] ),

        'CALENDAR'[Date] >= DateStartOfMonth

            && 'CALENDAR'[Date] <= SelectedDate

    )

RETURN

    _ValuesThisYear

 

If this does not work, could you please share some sample data without sensitive information and expected output.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi, @Jan_Cools 

 

May I ask if this is the expected output you are looking for? Based on your description, I have created many measures to achieve the effect you are looking for. Following picture shows the effect of the display.

vyaningymsft_2-1703577386476.png

Measures:

 

Remaining_Work_Days =

VAR remaining_Work_Days =

    NETWORKDAYS ( SELECTEDVALUE ( 'Table'[Date] ), ENDOFMONTH ( 'Table'[Date] ), 1 )

RETURN

    remaining_Work_Days



SameWorkingDayLastYear =

VAR SelectedDate =

    SELECTEDVALUE ( 'Table'[Date] )

VAR SameDayLastYear =

    SAMEPERIODLASTYEAR ( 'Table'[Date] )

VAR SameMonthLastYear =

    EOMONTH ( SelectedDate, -12 )

VAR WorkingDaysLastYear =

    NETWORKDAYS ( SameDayLastYear, SameMonthLastYear )

RETURN

    WorkingDaysLastYear



TrueValuesLastYear =

VAR DIFFDAYS = [Remaining_Work_Days] - [SameWorkingDayLastYear]

VAR SelectedDate =

    SELECTEDVALUE ( 'Table'[Date] )

VAR SameDayLastYear =

    SAMEPERIODLASTYEAR ( 'Table'[Date] )

VAR StartMonthLastYear =

    EOMONTH ( SelectedDate, -13 ) + 1

VAR _tureSameDayLastYear =

    SWITCH (

        DIFFDAYS,

        -1,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear + 1 ) = 7, SameDayLastYear + 3,

                WEEKDAY ( SameDayLastYear + 1 ) = 1, SameDayLastYear + 2,

                SameDayLastYear + 1

            ),

        -2,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear + 2 ) = 7, SameDayLastYear + 4,

                WEEKDAY ( SameDayLastYear + 2 ) = 1, SameDayLastYear + 3,

                SameDayLastYear + 2

            ),

        -3,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear + 3 ) = 7, SameDayLastYear + 5,

                WEEKDAY ( SameDayLastYear + 3 ) = 1, SameDayLastYear + 4,

                SameDayLastYear + 3

            ),

        1,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear - 1 ) = 7, SameDayLastYear - 2,

                WEEKDAY ( SameDayLastYear - 1 ) = 1, SameDayLastYear - 3,

                SameDayLastYear - 1

            ),

        2,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear - 2 ) = 7, SameDayLastYear - 4,

                WEEKDAY ( SameDayLastYear - 2 ) = 1, SameDayLastYear - 3,

                SameDayLastYear - 2

            ),

        3,

            SWITCH (

                TRUE (),

                WEEKDAY ( SameDayLastYear - 3 ) = 7, SameDayLastYear - 5,

                WEEKDAY ( SameDayLastYear - 3 ) = 1, SameDayLastYear - 4,

                SameDayLastYear - 3

            ),

        SameDayLastYear

    )

VAR _ValuesLastYear =

    CALCULATE (

        SUM ( 'CALENDAR'[Value] ),

        'CALENDAR'[Date] >= StartMonthLastYear

            && 'CALENDAR'[Date] <= _tureSameDayLastYear

    )

RETURN

    _ValuesLastYear



ValuesThisYear =

VAR SelectedDate =

    SELECTEDVALUE ( 'Table'[Date] )

VAR DateStartOfMonth =

    EOMONTH ( SelectedDate, -1 ) + 1

VAR _ValuesThisYear =

    CALCULATE (

        SUM ( 'CALENDAR'[Value] ),

        'CALENDAR'[Date] >= DateStartOfMonth

            && 'CALENDAR'[Date] <= SelectedDate

    )

RETURN

    _ValuesThisYear

 

If this does not work, could you please share some sample data without sensitive information and expected output.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Perfect @Anonymous Yang!

 

seems to be working as expected.

 

Thanks a lot.

saudansari
Helper II
Helper II

If you can share sample file it will be great

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.