Forum Discussion
How to get previous row in Matrix
Hi Folks, Need your expertise to get the previous row if present row is null using DAX (for each region).
| Region | Category | Sub-Category | Profit | YearMonth | Sales |
| East | A | A1 | 0 | 202312 | 100 |
| East | A | A3 | 1 | 202401 | 300 |
| East | B | B1 | 2 | 202402 | |
| South | C | C1 | 3 | 202312 | 2100 |
| South | C | C4 | 4 | 202401 | |
| South | C | C3 | 5 | 202402 | 2300 |
| North | C | C5 | 6 | 202312 | |
| North | C | C2 | 7 | 202401 | 2200 |
| North | B | B2 | 8 | 202402 | 1200 |
| West | A | A4 | 9 | 202312 | 400 |
| West | A | A2 | 10 | 202401 |
MarshalSK correct.
I'm thinking I misread the request but you can use the below to achieve the outcome you want rather than the first solution I proposed (Column 2). Just adjust the name of your table and columns to match yours and you will get the output that matches your initial post.
Column 2 = IF( ISBLANK ( Table2[Sales] ) , CALCULATE( MAX( 'Table2'[Sales] ) , FILTER ( Table2 , [Region] = EARLIER ( [Region] ) && [YearMonth] < EARLIER ( [YearMonth] ) ) ) , [Sales] )Hope this helps mate! 🙂
Theo
5 Replies
- TheoCCommunity Champion
MarshalSK correct.
I'm thinking I misread the request but you can use the below to achieve the outcome you want rather than the first solution I proposed (Column 2). Just adjust the name of your table and columns to match yours and you will get the output that matches your initial post.
Column 2 = IF( ISBLANK ( Table2[Sales] ) , CALCULATE( MAX( 'Table2'[Sales] ) , FILTER ( Table2 , [Region] = EARLIER ( [Region] ) && [YearMonth] < EARLIER ( [YearMonth] ) ) ) , [Sales] )Hope this helps mate! 🙂
Theo