Forum Discussion
How to calculate Recent Week and Past Week
Hello All,
I'm trying to create new column to get information on Recent Week and Past Week. Here is DAX use:
1. Check Current or Prior Wk = If( 'Pending Items'[Load Week]= MAXX(FILTER('Pending Items','Pending Items'[New_Adjusted_LoadDateWeek] = MAX('Pending Items'[New_Adjusted_LoadDateWeek])),'Pending Items'[Load Week]), "Recent Week", ( If( 'Pending Items'[Load Week]= MAXX(FILTER('Pending Items','Pending Items'[Load Week]<>MAXX(FILTER('Pending Items','Pending Items'[New_Adjusted_LoadDateWeek] = MAX('Pending Items'[New_Adjusted_LoadDateWeek])),'Pending Items'[Load Week])),'Pending Items'[Load Week]), "Past Week","(Ensure Untick) History Week" ) ) )
This formula giving correct value for Recent Week but wrong value for Past Week
| Load Date | Load Week | Current and Prior Load Week | Number of ID | Expected Result |
| 1/20/2023 | 1 | 16096 | ||
| 1/17/2024 | 1 | 6003 | ||
| 1/20/2023 | 2 | 16072 | ||
| 1/17/2024 | 2 | 6141 | ||
| 1/21/2023 | 3 | 15485 | ||
| 1/20/2024 | 3 | 5746 | ||
| 1/28/2023 | 4 | 15478 | ||
| 1/28/2024 | 4 | 5840 | ||
| 2/5/2023 | 5 | 15751 | ||
| 1/31/2024 | 5 | 6132 | Past Week | |
| 2/3/2024 | 5 | 5887 | ||
| 2/11/2023 | 6 | 15764 | ||
| 2/5/2024 | 6 | 6180 | Current Week | |
| 2/18/2023 | 7 | 15559 | ||
| 2/25/2023 | 8 | 15701 | ||
| 3/4/2023 | 9 | 17710 | ||
| 3/18/2023 | 10 | Past Week | 15146 | |
| 3/18/2023 | 11 | Current Week | 18249 |
Hi,
I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.
It is for creating a new column.
expected result CC = VAR _calendartable = ADDCOLUMNS ( CALENDAR ( DATE ( YEAR ( MIN ( Data[Load Date] ) ), 1, 1 ), DATE ( YEAR ( MAX ( Data[Load Date] ) ), 12, 31 ) ), "Year", YEAR ( [Date] ), "Weeknumber", WEEKNUM ( [Date], 21 ) ) VAR _currentweekyear = MAXX ( FILTER ( _calendartable, [Date] = TODAY () ), [Year] ) VAR _currentweekweeknumber = MAXX ( FILTER ( _calendartable, [Date] = TODAY () ), [Weeknumber] ) VAR _prevweekyear = MAXX ( FILTER ( _calendartable, [Date] = TODAY () - 7 ), [Year] ) VAR _prevweekweeknumber = MAXX ( FILTER ( _calendartable, [Date] = TODAY () - 7 ), [Weeknumber] ) VAR _currentweeklist = SUMMARIZE ( FILTER ( _calendartable, [Year] = _currentweekyear && [Weeknumber] = _currentweekweeknumber ), [Date] ) VAR _prevweeklist = SUMMARIZE ( FILTER ( _calendartable, [Year] = _prevweekyear && [Weeknumber] = _prevweekweeknumber ), [Date] ) RETURN SWITCH ( TRUE (), Data[Load Date] IN _currentweeklist, "Current Week", Data[Load Date] IN _prevweeklist, "Previous Week" )
3 Replies
- sayaliredij
Solution Sage
HI eryka_90
For the First columm ,which is just related to current week and past week i assume ,
I tried following measure.
Check Current or Prior Wk =
var currentweek = WEEKNUM(TODAY())
var currentYear = Year(TODAY())
var currentdate = TODAY()
var pastweek = WEEKNUM(TODAY() - 7)
var pastweekyear = YEAR(TODAY() - 7)
RETURN
IF(AND(currentweek = WEEKNUM('Table'[Load Date]),currentYear = YEAR('Table'[Load Date])),"Current Week",
IF(AND(pastweek = WEEKNUM('Table'[Load Date]),pastweekyear = YEAR('Table'[Load Date])),"Past Week",BLANK()))although this data has more than one entries from the past date . so could you clarify that little bit
for second measure
Try following measure
New_Current and Prior Load Week =
var maxload_week = MAXX(FILTER('Table','Table'[Number of ID] = MAX('Table'[Number of ID])),'Table'[Load Week])
RETURN IF('Table'[Load Week] = maxload_week, "Max Load week", blank())
It would return you max load week and the you can adjust it for past week as wellPlease check if this helps
Thanks and Regards,
Sayali
Please mark the question solved when done and consider giving a thumbs up if posts are helpful!!
- Jihwan_Kim
Super User
Hi,
I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.
It is for creating a new column.
expected result CC = VAR _calendartable = ADDCOLUMNS ( CALENDAR ( DATE ( YEAR ( MIN ( Data[Load Date] ) ), 1, 1 ), DATE ( YEAR ( MAX ( Data[Load Date] ) ), 12, 31 ) ), "Year", YEAR ( [Date] ), "Weeknumber", WEEKNUM ( [Date], 21 ) ) VAR _currentweekyear = MAXX ( FILTER ( _calendartable, [Date] = TODAY () ), [Year] ) VAR _currentweekweeknumber = MAXX ( FILTER ( _calendartable, [Date] = TODAY () ), [Weeknumber] ) VAR _prevweekyear = MAXX ( FILTER ( _calendartable, [Date] = TODAY () - 7 ), [Year] ) VAR _prevweekweeknumber = MAXX ( FILTER ( _calendartable, [Date] = TODAY () - 7 ), [Weeknumber] ) VAR _currentweeklist = SUMMARIZE ( FILTER ( _calendartable, [Year] = _currentweekyear && [Weeknumber] = _currentweekweeknumber ), [Date] ) VAR _prevweeklist = SUMMARIZE ( FILTER ( _calendartable, [Year] = _prevweekyear && [Weeknumber] = _prevweekweeknumber ), [Date] ) RETURN SWITCH ( TRUE (), Data[Load Date] IN _currentweeklist, "Current Week", Data[Load Date] IN _prevweeklist, "Previous Week" )- eryka_90
Helper I
Hi Jihwan_Kim,
Your solution give the results as expected. Eventhough I need to do some filtering to have only one previous week.
Thank you for helping 😃