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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
vvenditt
New Member

get value from the previous month

hello, hope you all are well!
I have a problem in a DAX measure.
I need to capture the previous result.
normally I would use DATEADD or PREVIOUSMONTH for this, but my problem is:
in my example, I don't have data for month 3, so in the analysis for month 4 I need to capture the last one before it with value
in this case month 2

 

here a small sample of the data:dados.PNG

 

Can someone help me? Thank you very much!
1 ACCEPTED SOLUTION

5 REPLIES 5
Anonymous
Not applicable

Hello I tried this DAX and its very useful but may I ask how about if there's an order that needs to fill in like the image below. I need ($1535) to be in Mar 2022 since its the next month not in Apr 2022.
 2nd column is the current month and 3rd column is the previous month2nd column is the current month and 3rd column is the previous month
2nd column is the current month and 3rd column is the previous month.
Thanks in advance.

Greg_Deckler
Community Champion
Community Champion

@vvenditt You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



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

Thank you very much for your help. the material will help me as a reference, but I still haven't been able to solve my problem.

the main point here is this:
if I'm evaluating the line of period 4, I want to compare it with period 3, but if there is no value in period 3, I want to compare it to period 2.

in my case I do not need to accumulate, but rather pay the amount prior to the period of the valuation context

hello I managed to solve it with this DAX code:

previous result =
var period_context = MAX (data [period])

var previous_period =
CALCULATE(
   MAX (data [period]),
   FILTER(
      ALL (data [period]),
      data [period] <period_context &&
      SUM (data [value]) <> BLANK ()
   )
)

var previous_month_value =
CALCULATE(
   SUM (data [value]),
   FILTER(
      ALL (data [period]),
      data [period] = previous_period
   )
)

Return
if(
   ISINSCOPE (data [period]),
   previous_month_value
)

tks

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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