Forum Discussion

fcb2026's avatar
fcb2026
Frequent Visitor
3 months ago
Solved

Issue with SAMEPERIODLASTYEAR and Manual Time Intelligence

Hi, the visual on the right works as expected, as it uses built-in time intelligence and automatic date handling. However, I would like to use the visual on the left without automatic time int...
  • v-saisrao-msft's avatar
    v-saisrao-msft
    3 months ago

    Hi fcb2026,

    Thank you Ashish_Mathur Natarajan_M johnt75, for your insights.

    I was able to reproduce the issue in the PBIX file you provided.

    The problem occurs because the current PY measure relies on DATEADD() or SAMEPERIODLASTYEAR(), which compare exact calendar dates rather than using the custom WD_Running_Total (working-day sequence) logic.

     

    Thank you.

  • johnt75's avatar
    johnt75
    3 months ago

    You need to separate the working days from the date dimension. Create a new table like

    Working Day = SELECTCOLUMNS(
        GENERATESERIES( 1, 23 ),
        "Working Day", [Value] 
    )

    Create a one-to-many relationship from this new table to your Date table. Use the column from this table in your visuals, and change your PY measure to

    PY = 
    VAR _CurrentYear =
        CALCULATE(
            MAX( 'DATE'[Year] ),
            REMOVEFILTERS( 'Working Day' )
        )
    VAR _CurrentMonth =
        CALCULATE(
            MAX( 'DATE'[Period] ),
            REMOVEFILTERS( 'Working Day' )
        )
    VAR _CurrentWD = VALUES( 'Working Day'[Working Day] )
    RETURN
        CALCULATE(
            SUM( SALES_TABLE[Sales] ),
            REMOVEFILTERS( 'DATE' ),
            _CurrentWD,
            'DATE'[Year] = _CurrentYear - 1,
            'DATE'[Period] = _CurrentMonth
        )

    See attached PBIX for sample.