Forum Discussion
Line chart for 3 different year
- 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 fordiscount_cyafter 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_cymeasure should only show values where data exists:
Example:
Discount_CY =
IF(
SELECTEDVALUE('FactTable'[Year]) = MAX('SelectedYearTable'[Year]),
SUM('FactTable'[discount_cy])
)
Fordiscount_pyanddiscount_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 !!
-
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_cymeasure should only show values where data exists:
Example:
Discount_CY =
IF(
SELECTEDVALUE('FactTable'[Year]) = MAX('SelectedYearTable'[Year]),
SUM('FactTable'[discount_cy])
)
Fordiscount_pyanddiscount_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 !!
johnbasha33 what i understand we have two tables weektable and facttable but what is this selectedyeartable? could you elaborate?