Forum Discussion
Value from previous row grouping within groups
Dear Community, pelease help
New but eager to learn Power BI:-)
I am strugling with finding a solution that gives me previous Date/row value and also grouping it by the key/items
This it to have a history that shows start and end dates.
This is how it would look like:
Before:
| Item | Country | Date |
| 1 | DK | 03/04/2020 |
| 2 | DK | 03/04/2020 |
| 4 | SE | 04/04/2020 |
| 2 | DE | 03/05/2020 |
| 3 | DK | 03/05/2020 |
| 3 | DK | 21/05/2020 |
| 1 | SE | 05/04/2020 |
| 1 | DE | 10/04/2020 |
| 2 | SE | 03/06/2020 |
| 4 | DE | 10/04/2020 |
| 2 | DK | 10/06/2020 |
| 3 | DK | 21/05/2020 |
| 3 | SE | 21/05/2020 |
| 1 | DE | 20/04/2020 |
Aften:
| Item | Country | ChangeDate | PreviousDate | Weekdays |
| 1 | DK | 03/04/2020 | 03/04/2020 | 1 |
| 1 | SE | 05/04/2020 | 03/04/2020 | 1 |
| 1 | DE | 10/04/2020 | 05/04/2020 | 5 |
| 1 | DE | 20/04/2020 | 10/04/2020 | 7 |
| 2 | DK | 03/04/2020 | 03/04/2020 | 1 |
| 2 | DE | 03/05/2020 | 03/04/2020 | 21 |
| 2 | SE | 03/06/2020 | 03/05/2020 | 23 |
| 2 | DK | 10/06/2020 | 03/06/2020 | 6 |
| 3 | DK | 03/05/2020 | 03/05/2020 | 0 |
| 3 | DK | 21/05/2020 | 03/05/2020 | 14 |
| 3 | DK | 21/05/2020 | 21/05/2020 | 1 |
| 3 | SE | 21/05/2020 | 21/05/2020 | 1 |
| 4 | SE | 04/04/2020 | 04/04/2020 | 0 |
| 4 | DE | 10/04/2020 | 04/04/2020 | 5 |
Anonymous ,
You can get
previous Date = coalesce(maxx(filter(Table,[Item] =earlier([Item]) && [Country] =earlier([Country]) && [ChangeDate] <earlier([ChangeDate]) ),[ChangeDate]),[ChangeDate])
Date diff = ( [ChangeDate] ,[previous Date],Day)
For the business days you need to use calendar . refer
https://www.sqlbi.com/articles/counting-working-days-in-dax/
1 Reply
- amitchandakSuper User
Anonymous ,
You can get
previous Date = coalesce(maxx(filter(Table,[Item] =earlier([Item]) && [Country] =earlier([Country]) && [ChangeDate] <earlier([ChangeDate]) ),[ChangeDate]),[ChangeDate])
Date diff = ( [ChangeDate] ,[previous Date],Day)
For the business days you need to use calendar . refer
https://www.sqlbi.com/articles/counting-working-days-in-dax/