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
harshagraj
Post Partisan
Post Partisan

Top display previous 4 weeks data

Hello all,

I am on direct query mode
I have two columns Fiscal Week and Amount and i have to display previous 4 weeks(25,26,27,28) in a table. Fiscal week column will have 1-52 weeks and amount will have data only till 28th week. I tried measure like
Var _max week = calculate(max(fiscal_week,Filter(Amount<>Blank)
Var_previousweek = _maxweek-3
Return
Calculate(Sum(Amount), Filter(fiscal_week >=_previousweek && fiscal_week<= _maxweek))) and this worked for a card and not for a table.

WeeksAmount

16773
27117
37112
47539
56837
66257
76398
86036
95698
106740
117097
127516
136480
145746
155355
167021
175975
187042
197344
207290
216615
227794
236363
246244
256990
267432
277029
285602
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@harshagraj , a small change, Try

 

Var _max week = maxX(filter(allselected(Table), [Amount]<>Blank), [fiscal_week])
Var_previousweek = _maxweek-3
Return
Calculate(Sum(Amount), Filter(Table, [fiscal_week] >=_previousweek && [fiscal_week] <= _maxweek))

View solution in original post

wow worked like a charm. Thanks a lot.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi, @harshagraj 

 

Please try the below calcualated measure.

 

Last four weeks =
VAR maxweek =
CALCULATE (
MAX ( Data[Weeks] ),
FILTER ( ALL ( Data ), NOT ISBLANK ( Data[Amount] ) )
)
VAR lastfourweeksamount =
CALCULATE (
SUM ( Data[Amount] ),
KEEPFILTERS (
FILTER ( ALL ( Data ), Data[Weeks] >= maxweek - 3 && Data[Weeks] <= maxweek )
)
)
RETURN
lastfourweeksamount

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@harshagraj , a small change, Try

 

Var _max week = maxX(filter(allselected(Table), [Amount]<>Blank), [fiscal_week])
Var_previousweek = _maxweek-3
Return
Calculate(Sum(Amount), Filter(Table, [fiscal_week] >=_previousweek && [fiscal_week] <= _maxweek))

Hi @amitchandak could you please help me to take difference of previous week also? I want to calculate change in % from previous week.

harshagraj_1-1618067140334.png

 

 

wow worked like a charm. Thanks a lot.

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.