The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Basis on below data I want to add a calculated column with Week Description
I've done it in excel by typing it manually.
Also my week is starting from Thursday and ends on Wednesday hence I've Used this function to get the weekday
WEEKDAY('Calendar'[date],14)
Requesting you to help me with a dax code which can be used to create a new calculated column with week information as shown below in third column.
The logic would be : If the date is current week then the value will be "This Week" else if the date is in last week then "This Week -1" else if the date is in last to last week then "This Week - 2" and so on.
Date | Weekday | WeekDesc |
01-12-2021 | 7 | This Week -3 |
02-12-2021 | 1 | This Week -2 |
03-12-2021 | 2 | This Week -2 |
04-12-2021 | 3 | This Week -2 |
05-12-2021 | 4 | This Week -2 |
06-12-2021 | 5 | This Week -2 |
07-12-2021 | 6 | This Week -2 |
08-12-2021 | 7 | This Week -2 |
09-12-2021 | 1 | This Week -1 |
10-12-2021 | 2 | This Week -1 |
11-12-2021 | 3 | This Week -1 |
12-12-2021 | 4 | This Week -1 |
13-12-2021 | 5 | This Week -1 |
14-12-2021 | 6 | This Week -1 |
15-12-2021 | 7 | This Week -1 |
16-12-2021 | 1 | This Week |
17-12-2021 | 2 | This Week |
18-12-2021 | 3 | This Week |
19-12-2021 | 4 | This Week |
20-12-2021 | 5 | This Week |
21-12-2021 | 6 | This Week |
Solved! Go to Solution.
Hi @Anonymous
Try this code to add a new column:
WeekDesc =
Var _A = WEEKNUM(today(),14)
Var _B = WEEKNUM([Date],14)
Var _C = _B-_A
return
if(_B=_A,"This Week","This Week" & _C)
output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/
Hi @Anonymous
Try this code to add a new column:
WeekDesc =
Var _A = WEEKNUM(today(),14)
Var _B = WEEKNUM([Date],14)
Var _C = _B-_A
return
if(_B=_A,"This Week","This Week" & _C)
output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/
Hi,
Like Syk mentioned you can use datediff. Additionally you can combine it with concatenate to get the exact result you described:
Proud to be a Super User!
The datediff function should work for you! Try this out for creating a new column with dax
WeekDiff =
DATEDIFF(today(),'Table'[Date],WEEK)
User | Count |
---|---|
28 | |
11 | |
8 | |
6 | |
5 |
User | Count |
---|---|
35 | |
14 | |
12 | |
9 | |
7 |