Forum Discussion

DiKi-I's avatar
DiKi-I
Post Partisan
2 years ago

need help with PY calculation

Hi ,

I have created a period table with folliwng scripts. I want to give user flixibilty to select period and then this table is related to date dimension. How can I do the PY calculation when user selects rolling period like rolling one year? How I can design my dashboard? Need help to with these time intelligence calculation

Period = UNION(
ADDCOLUMNS(
        CALENDAR(TODAY() - 7, TODAY()),
        "Type", "Last 7 days",
        "Sort", 1
    ),
     ADDCOLUMNS(
        CALENDAR(TODAY() - 30, TODAY()),
        "Type", "Last 30 days",
        "Sort", 2
    ),
ADDCOLUMNS(
        CALENDAR(TODAY() - 60, TODAY()),
       "Type", "Last 60 days",
        "Sort", 3
    )
  ,
    ADDCOLUMNS(
        PREVIOUSQUARTER(DATESQTD('Calendar'[Date])),
        "Type", "Last Qtr",
        "Sort", 5
    ),
    ADDCOLUMNS(
        PREVIOUSYEAR(DATESYTD('Calendar'[Date])),
        "Type", "Last Year",
        "Sort", 6
    ),
    ADDCOLUMNS(
        CALENDAR(MIN('Calendar'[Date]),TODAY()),
        "Type", "All Period",
        "Sort", 7
    ),
    ADDCOLUMNS(
        CALENDAR(MIN('Calendar'[Date]),MAX('Calendar'[Date])),
        "Type", "Custom",
        "Sort", 8
    ) ,
     ADDCOLUMNS(
        CALENDAR(
            DATE(YEAR(MAX('Calendar'[Date])), 1, 1),
            TODAY()
        ),
        "Type", "Current Year",
        "Sort", 9
    ),
    ADDCOLUMNS(
        CALENDAR(
            TODAY() - 28,
           TODAY()
        ),
        "Type", "Rolling 4 Weeks",
        "Sort", 10
    ),
    ADDCOLUMNS(
        CALENDAR(
            TODAY() - 365,
            TODAY()
        ),
        "Type", "Rolling 1 Year",
        "Sort", 11
    ),
    ADDCOLUMNS(
        CALENDAR(
           TODAY() - 1825,
            TODAY()
        ),
        "Type", "Rolling 5 Years",
        "Sort", 12
    )
)

3 Replies

  • If you want to give them flexibility you should use the Advanced filtering in the filter pane and teach your users how to use that. 

    • DiKi-I's avatar
      DiKi-I
      Post Partisan

      Thanks for your response. But I am looking for PY calculation based on period selected, so that it takes the same number of days dynamically and do the previous period calculation. 
      If rolling 1 year starts from 5-nov-2022 and ends at 5-nov-2023. Then then the PY will dynamically get the start date and end date. 

      • lbendlin's avatar
        lbendlin
        Super User

        Use the WINDOW function for that, or EDATE(-12)