Forum Discussion
Count based on variable date range and start date
- 1 year ago
Hi unknown917 please try this
create a calculated column in your sales table for the week buckets
Week_Bucket =VAR ReOpenDate = LOOKUPVALUE('reopen'[Reopen Date], 'reopen'[ID], 'sales'[ID])VAR DaysSince = DATEDIFF(ReOpenDate, 'sales'[Date], DAY)RETURNSWITCH(TRUE(),DaysSince >= 0 && DaysSince < 28, "Week 1-4 After",DaysSince >= 28 && DaysSince < 56, "Week 5-8 After",DaysSince >= 56 && DaysSince < 84, "Week 9-12 After",DaysSince < 0 && DaysSince >= -28, "Week 1-4 Before",DaysSince < -28 && DaysSince >= -56, "Week 5-8 Before",DaysSince < -56 && DaysSince >= -84, "Week 9-12 Before","Other")And then create the measure to sum the sales based on the buckets
Sales_by_Weeks =
VAR SelectedWeek = SELECTEDVALUE('SalesData'[Week_Bucket])
RETURN
CALCULATE(SUM('SalesData'[Sales Qty]), 'SalesData'[Week_Bucket] = SelectedWeek)
Hi unknown917
As I understand, create a RelativePeriod column that groups sales into 4-week periods before and after reopening by dividing the day difference by 28.
And the Sales_4WeekPeriod measure then sums sales for each period, allowing performance comparison over time.
- unknown9171 year agoHelper IV
Thanks, techies -
this resulted in returning all sales for the entire date range in 2nd table. I need to be able to represent the 4 week increments, based on the go -live date