Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Line chart for 3 different year

I have a line chart with three different measures for the  y-axis, discount_cy, discount_py, Discount_ppy and week number on x-axis, suppose 2024 and 2023 have all 52 weeks data but 2025 have only d...
  • johnbasha33's avatar
    1 year ago

    Hi Anonymous 

    You need a separate Week Table that always has all 52 weeks.
    This table will act as the X-axis and stay steady even if fact table has fewer rows.
    Then you modify your DAX measures to show blank for discount_cy after week 14, but still show full 52 weeks for PY and PPY.

    Step 1: Create a Week Table

    You can create a simple calculated table like this:

    WeekTable =
    ADDCOLUMNS(
    CALENDAR(
    DATE(2023,1,1),
    DATE(2025,12,31)
    ),
    "WeekNumber", WEEKNUM([Date],2),
    "Year", YEAR([Date])
    )

    Or if you want it even simpler, just Week numbers 1 to 52:

    WeekTable =
    ADDCOLUMNS(
    GENERATESERIES(1,52,1),
    "WeekNumber", [Value]
    )

    Step 2: Create a Relationship

    • Connect WeekTable[WeekNumber] 👉 FactTable[WeekNumber]

    • Single-direction relationship (WeekTable filters FactTable)

      Step 3: Modify your DAX Measures

      Your discount_cy measure should only show values where data exists:
      Example:

      Discount_CY =
      IF(
      SELECTEDVALUE('FactTable'[Year]) = MAX('SelectedYearTable'[Year]),
      SUM('FactTable'[discount_cy])
      )
      For discount_py and discount_ppy, ignore Selected Year filter:
      Example:

      Discount_PY =
      CALCULATE(
      SUM('FactTable'[discount_py]),
      'FactTable'[Year] = MAX('SelectedYearTable'[Year]) - 1
      )

      Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!