Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Lucy_Ramirez
Frequent Visitor

Last Week Value

Hello team,

I need help to bring the value of last week in my dashboard. I use the following dax formula and the values are correct.

Last Week Final Inventory = CALCULATE ( [FinalInventory],FILTER(ALL(Calendar),Calendar[Year]=SELECTEDVALUE(Calendar[Year])&&Calendar[Week Number]=SELECTEDVALUE(Calendar[Week Number])-1))

But my data is from 2021 to 2023. If I select week 1 of the year 2023, I would like to see week 52 of the year 2022. Currently if I am in week 1 of the year 2023 is blank.

Lucy_Ramirez_0-1672874783995.png

What im doing grong?

 

Any coment will help me.

Thank you so much! 😄

 

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi, @Lucy_Ramirez 

Accordin to your description, you want to get the last week value by the "Year and week". 

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1672881753850.png

(2)We need to create a 'Date' table as a dimension table:

Date = ADDCOLUMNS( 
CALENDAR(FIRSTDATE('Table'[Date]),LASTDATE('Table'[Date])),
"Year", YEAR([Date]),
"Week", weeknum([Date]),
"Year_Week", year([Date]) * 100 + weeknum([Date])
)

The relationship is as belows:

vyueyunzhmsft_1-1672881800856.png

(3)Then i create a measure to sum of the value like you:

FinalInventory = SUM('Table'[Value])

(4)Then we can create a measure like this:

Last Week = var _curyearweek = MAX('Date'[Year_Week])
var _t = SUMMARIZE(ALLSELECTED('Date') , 'Date'[Year_Week] ,"Value" , [FinalInventory])
var _maxyearweek =MAXX( FILTER( _t , [Year_Week] <_curyearweek) , [Year_Week])
var _t2 = FILTER(_t, [Year_Week]=_maxyearweek)
return
MAXX(_t2,[Value])

(5)Then we can put the measure on the visual and we can meet your need:

vyueyunzhmsft_2-1672881857014.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
Ahmedx
Super User
Super User

maybe so:

 

Последняя неделя = 
 VAR _SelectWeek =
     SELECTEDVALUE ('Дата'[Неделя])
 VAR _LastYear =
     ВЫБРАННОЕЗНАЧЕНИЕ ('Дата'[Год]) - 1
 VAR _MaxWeek =
     ВЫЧИСЛИТЬ (МАКС ('Дата'[Неделя]),ФИЛЬТР (ВСЕ ('Дата'), 'Дата'[Год] = _LastYear))
 VAR _Результаты =
     ЕСЛИ (_SelectWeek = 1,
         ВЫЧИСЛИТЬ (СУММ('Таблица'[Значение]),УДАЛИТЬФИЛЬТРЫ('Дата'),
         'Дата'[Неделя] = _MaxWeek&& 'Дата'[Год] = _LastYear),
         ВЫЧИСЛИТЬ ( СУММА («Таблица» [Значение]), «Дата» [Неделя] = _SelectWeek - 1)
     )
 ВОЗВРАЩАТЬСЯ
     _Результаты  

 

 

 

 

v-yueyunzh-msft
Community Support
Community Support

Hi, @Lucy_Ramirez 

Accordin to your description, you want to get the last week value by the "Year and week". 

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1672881753850.png

(2)We need to create a 'Date' table as a dimension table:

Date = ADDCOLUMNS( 
CALENDAR(FIRSTDATE('Table'[Date]),LASTDATE('Table'[Date])),
"Year", YEAR([Date]),
"Week", weeknum([Date]),
"Year_Week", year([Date]) * 100 + weeknum([Date])
)

The relationship is as belows:

vyueyunzhmsft_1-1672881800856.png

(3)Then i create a measure to sum of the value like you:

FinalInventory = SUM('Table'[Value])

(4)Then we can create a measure like this:

Last Week = var _curyearweek = MAX('Date'[Year_Week])
var _t = SUMMARIZE(ALLSELECTED('Date') , 'Date'[Year_Week] ,"Value" , [FinalInventory])
var _maxyearweek =MAXX( FILTER( _t , [Year_Week] <_curyearweek) , [Year_Week])
var _t2 = FILTER(_t, [Year_Week]=_maxyearweek)
return
MAXX(_t2,[Value])

(5)Then we can put the measure on the visual and we can meet your need:

vyueyunzhmsft_2-1672881857014.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

ryan_mayu
Super User
Super User

@Lucy_Ramirez 

you are showing year 2022 and week num is 0, that's why it display blank

you can add an if statement:

 if (max(Calendar[Week Number])=1,

CALCULATE ( [FinalInventory],FILTER(ALL(Calendar),Calendar[Year]=SELECTEDVALUE(Calendar[Year])-1&&Calendar[Week Number]=52)),

CALCULATE ( [FinalInventory],FILTER(ALL(Calendar),Calendar[Year]=SELECTEDVALUE(Calendar[Year])&&Calendar[Week Number]=SELECTEDVALUE(Calendar[Week Number])-1)))





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.