Forum Discussion
Creating a calculated column that returns the first 52 weeks a store is open
- 11 months ago
Hi abyars
You can align all stores by “age since opening” with either a quick calculated column or a lightweight measure—no complex time-intelligence needed.
Option A (simplest): add WeekSinceOpen_1_52 on your fact:
WeekSinceOpen_1_52 :=
VAR OpenD = RELATED(Store[OpenDate])
VAR DaysFromOpen = DATEDIFF(OpenD, Fact[Date], DAY)
VAR WeekIdx = QUOTIENT(DaysFromOpen, 7) + 1
RETURN IF(DaysFromOpen >= 0 && WeekIdx <= 52, WeekIdx)
Then build a matrix: Rows = Store, Columns = WeekSinceOpen_1_52, Values = your KPI.
Option B (no new column):
create a helper table GENERATESERIES(1,52,1) and a measure that maps each week index back to real dates using the store’s min date (opening), with ALLEXCEPT to keep the store context.
This aligns Week 1..52 for every store regardless of calendar date.
If it helps, please hit Accept as Solution & give a Kudos so others can find it faster 🙌
- In Power BI Desktop, navigate to the Data view.
- Select your Sales table in the Fields pane.
- Click New column in the ribbon.
- Enter the following DAX formula:dax
Weeks Since Open = VAR CurrentSalesDate = 'Sales'[SalesDate] VAR StoreOpeningDate = LOOKUPVALUE( 'Stores'[StoreOpenDate], 'Stores'[StoreID], 'Sales'[StoreID] ) RETURN IF( CurrentSalesDate >= StoreOpeningDate, INT(DATEDIFF(StoreOpeningDate, CurrentSalesDate, WEEK)) + 1, BLANK() )- LOOKUPVALUE: This function retrieves the correct StoreOpenDate from the Stores table for each corresponding StoreID in your Sales table.
- DATEDIFF: This calculates the difference in weeks between the store's open date and the sales date.
- + 1: The DATEDIFF function starts counting from zero, so adding one makes the first week a more intuitive 1.
- IF: This ensures that only transactions that occurred after the store opened are counted.
- Select the Matrix visual from the Visualizations pane.
- Add Weeks Since Open to the Columns field.
- Add StoreID (or StoreName) to the Rows field.
- Add your desired measure, such as Total Sales, to the Values field.
- With the matrix visual selected, find the Filters pane.
- Expand the Weeks Since Open filter.
- Change the filter type to is less than or equal to.
- Enter 52 in the value box.