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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
NKBI2022
New Member

How to get last week value per each category

Hi All..

 

I want to return the last week value per category. Here are the data and the example:

 

WeekNoValueCategory
11A
22A
31A
12B
31B

 

I want to create a table that shows the selected week value and the n-1 selected week value. I'm currently using this measure:

LastWeekValue = calculate( sum('table'[Value]), FILTER(ALL('table'), 'table'[WeekNo]= SELECTEDVALUE('table'[WeekNo]) - 1))

 

And here's the result of the measure:

Assuming that the selected week no is 3

CategorySelectedWeekValueLastSelectedWeekValue
A12
B12

 

The measure is showing the right sum of value on previous week. However, the value is showing the same value on each category. (Category B shows value = 2, eventhough that it actually has no value on week 2).

 

Here's the desired output looks like :

Assuming that the selected week no is 3

CategorySelectedWeekValue (week no 3)LastSelectedWeekValue (week no 2)
A12
B10

 

Please help me to solve this.

 

Thank you so much!!!!!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @NKBI2022 ,

 

Please try like:

LastWeekValue = 
VAR _lastweek = SELECTEDVALUE('Table'[WeekNo]) - 1
VAR _last_week_value = CALCULATE(SUM('Table'[Value]),'Table'[WeekNo]=_lastweek) + 0
RETURN
_last_week_value

vcgaomsft_0-1669886227417.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @NKBI2022 ,

 

Please try like:

LastWeekValue = 
VAR _lastweek = SELECTEDVALUE('Table'[WeekNo]) - 1
VAR _last_week_value = CALCULATE(SUM('Table'[Value]),'Table'[WeekNo]=_lastweek) + 0
RETURN
_last_week_value

vcgaomsft_0-1669886227417.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors