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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

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
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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors