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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-cgao-msft
Community Support
Community Support

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
v-cgao-msft
Community Support
Community Support

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.