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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.