Forum Discussion

Kundan_RR's avatar
Kundan_RR
Frequent Visitor
1 year ago
Solved

Current Year week to Last Year same Week

Hi Everyone,
I wanted to build a visual which should show the revenue of current year selected week to previous year of same selected week alognwith legend on visual. I want to create a stack chart, for eg. If I select slicer year 2025-34 (year week) then it should show me 2 bar ie. 2025-34 week revenue with legend and 2024-34 week revenue with legend. 

Please help how to do this. 

  • Hi Kundan_RR ,

     

    I have replicated the scenario, It is not possible to generate the expected output visual which was provided by you. Please refer below PBIX file.

     

    Regards,

    Dinesh

14 Replies

  • Hi Kundan_RR 

    Below are the steps to follow:

    1. Create Date table

    Date =
    ADDCOLUMNS (
      CALENDAR ( DATE(2024,1,1), DATE(2025,12,31) ),
      "ISO Week", WEEKNUM ( [Date], 21 ),
      "ISO Year", YEAR ( [Date] - WEEKDAY ( [Date], 2 ) + 4 ),
      "Year-Week", FORMAT ( YEAR ( [Date] - WEEKDAY ( [Date], 2 ) + 4 ), "0000" )
                     & "-" & FORMAT ( WEEKNUM ( [Date], 21 ), "00" )
    )

    Mark this as Date table and relate it with your Sales table on OrderDate.

    2. Measures

    Total Sales = SUM ( Sales[Amount] )
    LY Same Week Sales =
    VAR CurYW = SELECTEDVALUE ( 'Date'[Year-Week] )
    VAR CurYear = VALUE ( LEFT ( CurYW, 4 ) )
    VAR CurWeek = VALUE ( RIGHT ( CurYW, 2 ) )
    RETURN
    CALCULATE (
      [Total Sales],
      KEEPFILTERS (
          FILTER ( ALL ( 'Date' ),
              'Date'[ISO Year] = CurYear - 1 &&
              'Date'[ISO Week] = CurWeek
          )
       )
    )

    3. Visual

    • Put a Slicer on Date[Year-Week] (single select).
    • Add a Clustered column chart with:
      • X-axis >> Year-Week
      • Values >> Total Sales and LY Same Week Sales

    Now when you select e.g. 2025-34 in the slicer, you’ll see two bars side-by-side:

    • Current Year (2025-34) sales
    • Last Year (2024-34) sales

    4. Optional polish

    • Rename measures to “Current Year” and “Last Year” for a cleaner legend.
    • Add a dynamic title:
    Chart Title =
    "Year-Week: " & SELECTEDVALUE('Date'[Year-Week]) & " - Current vs Last Year"

     

     

    • Kundan_RR's avatar
      Kundan_RR
      Frequent Visitor

      Hi Rohit,
      Thanks for your answer, but it didn't resolve the problem. 

    • SundarRaj's avatar
      SundarRaj
      Super User

      Can you share the dataset you're working with?

      Thanks

      • Kundan_RR's avatar
        Kundan_RR
        Frequent Visitor

        Hi SundarRaj, please find the sample dataset. 

        Qualified (40%)24079.6596810-May-24
        Qualified (40%)9301.810-May-24
        Qualified (40%)465092-May-24
        Qualified (40%)2325.452-May-24
        Qualified (40%)10802.090322-May-24
        Qualified (40%)24079.659682-May-24
        Qualified (40%)9301.82-May-24
        Active (100%)19460.7658110-May-24
        Active (100%)19460.765812-May-24
        Active (100%)19460.7658125-Apr-24
        Active (100%)19460.7658119-Apr-24
        Active (100%)19460.7658112-Apr-24
        Active (100%)19460.765815-Apr-24
        Active (100%)19460.7658128-Mar-24
        Active (100%)19460.7658122-Mar-24
        Active (100%)19460.7658115-Mar-24
        Active (100%)19460.765818-Mar-24
        Active (100%)19460.765811-Mar-24
        Active (100%)19460.7658123-Feb-24
        Active (100%)19460.7658116-Feb-24
        Active (100%)19460.765819-Feb-24
        Active (100%)19460.765812-Feb-24
        Active (100%)19460.7658126-Jan-24
        Active (100%)19460.7658119-Jan-24
        Active (100%)19460.7658112-Jan-24
        Active (100%)19460.765815-Jan-24
        Active (100%)1024.25083222-Aug-25
        Active (100%)1024.25083215-Aug-25
        Active (100%)1024.2508328-Aug-25
        Active (100%)1024.2508321-Aug-25
        Active (100%)1024.25083225-Jul-25
        Active (100%)1024.25083218-Jul-25
        Active (100%)1024.2508324-Jul-25
        Active (100%)1024.25083227-Jun-25
        Active (100%)1024.25083220-Jun-25
        Active (100%)1024.25083213-Jun-25
        Active (100%)1024.2508326-Jun-25
        Active (100%)1024.25083230-May-25
        Active (100%)1024.25083223-May-25
        Active (100%)1024.25083216-May-25
        Qualified (40%)24079.6596810-May-24
        Qualified (40%)9301.810-May-24
        Qualified (40%)465092-May-24
        Qualified (40%)2325.452-May-24
        Qualified (40%)10802.090322-May-24
        Qualified (40%)24079.659682-May-24
        Qualified (40%)9301.82-May-24
        Active (100%)1024.25083221-Mar-25
        Active (100%)1024.25083214-Mar-25
        Active (100%)1024.2508327-Mar-25
        Active (100%)1024.25083227-Feb-25
        Active (100%)1024.25083221-Feb-25
        Active (100%)1024.25083214-Feb-25
        Active (100%)1024.2508327-Feb-25
        Active (100%)1024.25083231-Jan-25
        Active (100%)1024.25083224-Jan-25
        Qualified (40%)24079.6596810-May-24
        Qualified (40%)9301.810-May-24
        Qualified (40%)465092-May-24
        Qualified (40%)2325.452-May-24
        Qualified (40%)10802.090322-May-24
        Qualified (40%)24079.659682-May-24
        Qualified (40%)9301.82-May-24
  • v-dineshya's avatar
    v-dineshya
    Community Support

    Hi Kundan_RR ,

    Thank you for reaching out to the Microsoft Community Forum.

     

    Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot). Do not include sensitive information. Do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided.

     

    Regards,

    Dinesh

      • v-dineshya's avatar
        v-dineshya
        Community Support

        Hi Kundan_RR ,

         

        I have replicated the scenario, It is not possible to generate the expected output visual which was provided by you. Please refer below PBIX file.

         

        Regards,

        Dinesh

  • Do you want to show 2025-34 and 2024-34 as the legend and not just current/previous year?