Forum Discussion
How to get previous values
Hi there,
I have a table like that:
| Market_Week | Sum Quantity |
| 2 | 705 |
| 3 | 8272 |
| 4 | 8285 |
| 6 | 8705 |
| 7 | 8717 |
| 8 | 8726 |
| 10 | 9211 |
| 12 | 40157 |
| 13 | 43308 |
| 15 | 47564 |
| 16 | 49146 |
And i want to get previous values like:
| Market_Week | Sum Quantity | Previous Sum Quantity |
| 2 | 705 | |
| 3 | 8272 | 705 |
| 4 | 8285 | 8272 |
| 6 | 8705 | 8285 |
| 7 | 8717 | 8705 |
| 8 | 8726 | 8717 |
| 10 | 9211 | 8726 |
| 12 | 40157 | 9211 |
| 13 | 43308 | 40157 |
| 15 | 47564 | 43308 |
| 16 | 49146 | 47564 |
How can I handle this?
Thank you and I look forward to your support.
Hi NQT1711
I am sure there are many ways to do this, but one way is to create a calculated column for the indexing by rankx, and then to create another calculated column bringing the previous row.
Best regards,
- Anonymous2 years ago
Hi NQT1711 ,
Creating calculated columns is indeed a good option, as DataNinja777 provides.
However, if your data model is too large, it may increase the memory burden since the calculated columns will actually be added to the data model.Perhaps create a measure is a good option, refer to the following formula:
MEASURE = MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Market_Week] < MAX ( 'Table'[Market_Week] ) ), [Sum Quantity] )Best Regards,
Adamk KongIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- AnonymousNot applicable
Hi NQT1711 ,
Creating calculated columns is indeed a good option, as DataNinja777 provides.
However, if your data model is too large, it may increase the memory burden since the calculated columns will actually be added to the data model.Perhaps create a measure is a good option, refer to the following formula:
MEASURE = MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Market_Week] < MAX ( 'Table'[Market_Week] ) ), [Sum Quantity] )Best Regards,
Adamk KongIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Kaviraj11Solution Sage
There's two way that you can do it now.
1. Create a Measure
var _selecteddate= FIRSTDATE('Calendar'[week])-1
var PreviousDayTotal=CALCULATE(SUM(QUANTITTY),TREATAS({_selecteddate},'Calendar'[week]))
RETURN
IF(SUM(QUANTITTY)=BLANK(),BLANK(), SUM(QUANTITTY))
2. New features
You can calculate the previous value using new calculation as well which is the prefered solution now.
Visual calculations (preview) | Microsoft Power BI Blog | Microsoft Power BI
- Wilson_Memorable Member
Kaviraj11,
I strongly disagree that visual calculations are the preferred solution.
They're still a preview feature. They are also specific to the visual only and cannot be reused anywhere else.
- DataNinja777Super User
Hi NQT1711
I am sure there are many ways to do this, but one way is to create a calculated column for the indexing by rankx, and then to create another calculated column bringing the previous row.
Best regards,