Forum Discussion
Calculation between periods
Hello,
I need a help with calculate the difference between 2 dates, for example:
I have this Table:
| Periods | Value A | Value B | %Value B |
| Week 1 | 680 | 475 | 69,85% |
| Week 2 | 677 | 466 | 68,83% |
| Week 3 | 640 | 438 | 68,44% |
| Week 4 | 646 | 457 | 70,74% |
And I need a colunm or a measure "Difference" that calculate de difference of colunm "%Value B" by Periods:
| Periods | Value A | Value B | %Value B | Difference |
| Week 1 | 680 | 475 | 69,85% | |
| Week 2 | 677 | 466 | 68,83% | -1,02% |
| Week 3 | 640 | 438 | 68,44% | -0,39% |
| Week 4 | 646 | 457 | 70,74% | 2,30% |
Anybody can help me?
tks.
Anonymous Add an Index column in Power Query Editor or a Sequential week column like this: Sequential - Microsoft Power BI Community. Then you can use the MTBF pattern. 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
3 Replies
- Greg_Deckler
Community Champion
Anonymous Add an Index column in Power Query Editor or a Sequential week column like this: Sequential - Microsoft Power BI Community. Then you can use the MTBF pattern. 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- AnonymousNot applicable
thanks for your help, but I dont understand the first pass:
"VAR __Current = [Value]"This [Value] is the sum of Value B?
tks
- Greg_Deckler
Community Champion
Anonymous In your case yes. The code is generic code, you have to adapt it to your particular table name and column names.