Forum Discussion
vvenditt
5 years agoNew 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:
Can someone help me? Thank you very much!5 Replies
- Greg_Deckler
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-TITHW/m-p/434008- vvendittNew Member
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- vvendittNew Member
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 )
- AnonymousNot 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 month
2nd column is the current month and 3rd column is the previous month.
Thanks in advance.