Forum Discussion
Calculated column using 'lookup' in same table
I'm trying to compute a caluculated column in the Calendar to show which period is current, past of future. Can't get my head around it how to do this.
The difficulty is that I need my calendar to be of week and period granularity, not on date level. I do have a Week Start Date.
Periods are sections of weeks. Sometimes 4 weeks, sometimes 5. Not much logic there.
We are now in Period 7, and I did manage to write a DAX that tells me that this week, we are in the current period. See screenshot below.
Next I need to do some sort of lookup.
- If Period =7, then lookup and find the string "This Period".
- If Period >7, then Future.
- If Periode <7, then Passed.
Your help is much appreciated!
- Anonymous4 years ago
Hi Steven-conance ,
According to your screenshot, I think we can determind [Period] based on [Week Start Date]. My code is based on this logic, we will calculate week start date based on today and then get period. Then use this dynamic period in switch.
Please try it to create a calculated column.
Passed/Current/Future Periods = VAR _WeekStart_Date = TODAY () - WEEKDAY ( TODAY (), 2 ) + 1 VAR _Period = CALCULATE ( SUM ( 'TableName'[Period] ), FILTER ( 'TableName', 'TableName'[Week Date Start] = _WeekStart_Date ) ) RETURN SWITCH ( TRUE (), [Period] > _Period, "Future", [Period] = _Period, "This Period", [Period] < _Period, "Past" )Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
8 Replies
- amitchandakSuper User
Steven-conance , to me=e it seems like that does not need lookup. a new column
Switch( True() ,
[Week] >7 , "Future",
[Week] = 7 , "This Period",
[Week] < 7 , "Past")
- Steven-conanceHelper I
In essence, yes. But how to make this dynamic? When we're in Period 8, it's supposed to change. Then Period 8 is the current period. And so on
- amitchandakSuper User
Steven-conance , try like
New column =
var _max = maxx(filter(Table, Table[Date] = Today()) , [Week] )
return
Switch( True() ,
_max >7 , "Future",
_max = 7 , "This Period",
_max < 7 , "Past")
Default Date Today/ This Month / This Year: https://www.youtube.com/watch?v=hfn05preQYA
- Steven-conanceHelper I
Thanks amitchandak but again the question remains. The "7" here will be a different number every 4 weeks, so how to make that dynamic?
- Steven-conanceHelper I
Anonymous not actually it's a 445 rythm. First period is 4 weeks, second period is 4 week, third period is 5 weeks.
And then x4 for a full year
- AnonymousNot applicable
Hi Steven-conance ,
According to your screenshot, I think we can determind [Period] based on [Week Start Date]. My code is based on this logic, we will calculate week start date based on today and then get period. Then use this dynamic period in switch.
Please try it to create a calculated column.
Passed/Current/Future Periods = VAR _WeekStart_Date = TODAY () - WEEKDAY ( TODAY (), 2 ) + 1 VAR _Period = CALCULATE ( SUM ( 'TableName'[Period] ), FILTER ( 'TableName', 'TableName'[Week Date Start] = _WeekStart_Date ) ) RETURN SWITCH ( TRUE (), [Period] > _Period, "Future", [Period] = _Period, "This Period", [Period] < _Period, "Past" )Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Steven-conanceHelper I
Thanks Anonymous, works like a charm. Today a new period started, and it switched exactly as intended. Thanks!