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
Anonymous
Not applicable

Previous week value same row

Hi,

 

i have a table with list of different categories and values by weekly.

as default dates are with week difference.

i need to show the previous week value along with the current week value in the table.

below is example data. for an instance if i have 23102 for 2/14/2006, i need to show what is the value for 2/7/2006.

if i do this it is summing up entire dataset

last7days =
Var PreWeek = Append1[OPR_DATE]-7
Return
CALCULATE(FIRSTNONBLANK(Append1[VALUE],Append1[VALUE]),FILTER(Append1,Append1[OPR_DATE]=PreWeek))
2/7/2006WHEATNon-CommercialCBT48924
2/7/2006WHEATNon-CommercialKCBT54586
2/7/2006WHEATNon-ReportableCBT55086
2/7/2006WHEATNon-CommercialCBT65702
2/7/2006WHEATNon-CommercialCBT93391
2/14/2006WHEATNon-ReportableCBT5741
2/14/2006WHEATNon-CommercialKCBT23102
2/14/2006WHEATNon-ReportableKCBT33330
2/14/2006WHEATNon-ReportableKCBT34973
2/14/2006WHEATNon-ReportableCBT41912
2/14/2006WHEATNon-CommercialKCBT51494
2/14/2006WHEATNon-CommercialCBT53453
2/14/2006WHEATNon-ReportableCBT60827
2/14/2006WHEATNon-CommercialCBT67174
2/14/2006WHEATNon-CommercialCBT87459
2/21/2006WHEATNon-CommercialCBT14811
2/21/2006WHEATNon-CommercialKCBT26683

@Pragati11 @amitchandak @Greg_Deckler @selimovd 

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@Anonymous Seems like a variation on MTBF. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-xiaotang
Community Support
Community Support

Hi @Anonymous 

you can try this measure,

Measure = 
var _lastWeek=MIN(Append1[OPR_DATE])-7
return CALCULATE(SUM(Append1[VALUE]),FILTER(ALLEXCEPT(Append1,Append1[WHEAT],Append1[Non],Append1[Category]),Append1[OPR_DATE]=_lastWeek))

result

vxiaotang_1-1630035745668.png

if you need column,

Column = 
var _lastWeek=Append1[OPR_DATE]-7
return CALCULATE(SUM(Append1[VALUE]),FILTER(ALLEXCEPT(Append1,Append1[WHEAT],Append1[Non],Append1[Category]),Append1[OPR_DATE]=_lastWeek))

result

vxiaotang_2-1630035809268.png

 

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

you can try this measure,

Measure = 
var _lastWeek=MIN(Append1[OPR_DATE])-7
return CALCULATE(SUM(Append1[VALUE]),FILTER(ALLEXCEPT(Append1,Append1[WHEAT],Append1[Non],Append1[Category]),Append1[OPR_DATE]=_lastWeek))

result

vxiaotang_1-1630035745668.png

if you need column,

Column = 
var _lastWeek=Append1[OPR_DATE]-7
return CALCULATE(SUM(Append1[VALUE]),FILTER(ALLEXCEPT(Append1,Append1[WHEAT],Append1[Non],Append1[Category]),Append1[OPR_DATE]=_lastWeek))

result

vxiaotang_2-1630035809268.png

 

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@Anonymous Seems like a variation on MTBF. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous


@ 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!:
The Definitive Guide to Power Query (M)

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

@Greg_Deckler thank you for your time.

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.