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

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

Reply
Anonymous
Not applicable

calcultate previous week according to the row selection dynamically in matrix

hi all,

 

what i want to achieve is that in Matrix, it could calculate previous week amount smartly according to the field that i put in row section: e.g. 

when i put country in Rows, it shows

halskwibskc_0-1664202483547.png

 

and if i put product in Rows, it will dynamtically change to

halskwibskc_1-1664202503792.png

 

I am able to get previous week amount by the following DAX, however the problem is, because i sepecify Country in the DAX, if i want to calculate product, I would need to create another measure for it. What I want is just 1 measure to achieve this dynamic change, is it possible? 

 

PreviousWeekPaidImpr =
var currentweeknum = SELECTEDVALUE(bq[weeknum cloumn])
return
CALCULATE([Paid Impr],FILTER(ALLEXCEPT(bq,bq[country]),bq[weeknum cloumn]= currentweeknum -1))
 
 
 
FYI, I tried 
 
PreviousWeekPaidImpr =
var currentweeknum = SELECTEDVALUE(bq[weeknum cloumn])
return
CALCULATE([Paid Impr],FILTER(ALL(bq),bq[weeknum cloumn]= currentweeknum -1))
 
but with this, it returns result: which is not what I want. 
halskwibskc_2-1664202532302.png

 

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

@Anonymous Maybe:

PreviousWeekPaidImpr =
var currentweeknum = SELECTEDVALUE(bq[weeknum cloumn])
var country = CALCULATE([Paid Impr],FILTER(ALLEXCEPT(bq,bq[country]),bq[weeknum cloumn]= currentweeknum -1))
var product = CALCULATE([Paid Impr],FILTER(ALLEXCEPT(bq,bq[product]),bq[weeknum cloumn]= currentweeknum -1))
RETURN
  IF(ISINSCOPE('bq'[country]),country,product)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

hi @Greg_Deckler thanks for the quick reply.

 

there are acutally more than 2 fields that i want to change in the Rows section. Apart from country and products which are already mentioned, there are also sizes, colours and clients etc. 
In this case, the IF function would not be able to cover all the scenario. 

Do you have a new solution for it? 

@Anonymous You could do a nested IF statement but a SWITCH TRUE would be better, like below. Also, are you using a Field Parameter or no?

PreviousWeekPaidImpr =
var currentweeknum = SELECTEDVALUE(bq[weeknum cloumn])
var country = CALCULATE([Paid Impr],FILTER(ALLEXCEPT(bq,bq[country]),bq[weeknum cloumn]= currentweeknum -1))
var product = CALCULATE([Paid Impr],FILTER(ALLEXCEPT(bq,bq[product]),bq[weeknum cloumn]= currentweeknum -1))
RETURN
  SWITCH(TRUE(),
    ISINSCOPE('bq'[country]),country,
    ISINSCOPE('bq'[product]),product,
    // more ISINSCOPE here
  )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

hi @Greg_Deckler  thanks for the reply! I tired the swtich to calcaulate the difference between this week and previous week. However, the issue with swtich is that the sum total of the difference is missing if i use swtich. Do you have a way to work around this? I need the total number for futhere calculation steps. 

halskwibskc_0-1664361943656.png

 

Anonymous
Not applicable

hi @Greg_Deckler  in case you missed this, I'm tagging here again.  it's highly appreciated if you have a solution for this, thanks!

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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