Forum Discussion
Transform table to another format
Hi,
I would like to transform data to another format so I can use it as an fact. It is data about tracking car rides.
From a source I receive the following data:
| CarNr | Date | StartDate/Time | EndDate/Time | Distance |
| 1 | 25-7-2023 | 25-07-23 7:20 AM | 25-07-23 7:24 AM | 0,1 |
| 1 | 25-7-2023 | 25-07-23 12:00 PM | 25-07-23 12:25 PM | 15 |
| 1 | 25-7-2023 | 25-07-23 1:18 PM | 25-07-23 1:53 PM | 15 |
| 1 | 25-7-2023 | 25-07-23 4:25 PM | 25-07-23 4:26 PM | 0,1 |
| 1 | 28-7-2023 | 28-07-23 7:12 AM | 28-07-23 9:46 AM | 19,8 |
| 1 | 28-7-2023 | 28-07-23 9:50 AM | 28-07-23 9:51 AM | 0,2 |
| 1 | 28-7-2023 | 28-07-23 2:09 PM | 28-07-23 2:25 PM | 8,9 |
| 1 | 28-7-2023 | 28-07-23 2:41 PM | 28-07-23 2:44 PM | 0,2 |
| 1 | 30-7-2023 | 30-07-23 8:57 AM | 30-07-23 9:20 AM | 5,4 |
| 1 | 30-7-2023 | 30-07-23 9:30 AM | 30-07-23 9:48 AM | 5,6 |
| 1 | 1-8-2023 | 30-07-23 9:57 AM | 30-07-23 9:59 AM | 0,2 |
| 2 | 26-7-2023 | 26-07-23 9:10 AM | 26-07-23 9:28 AM | 0,5 |
| 2 | 26-7-2023 | 26-07-23 9:28 AM | 26-07-23 9:32 AM | 0,8 |
| 2 | 26-7-2023 | 26-07-23 7:39 PM | 26-07-23 8:13 PM | 8,4 |
| 2 | 26-7-2023 | 26-07-23 8:22 PM | 26-07-23 8:43 PM | 8,9 |
| 2 | 26-7-2023 | 26-07-23 9:11 PM | 26-07-23 9:11 PM | 0 |
| 2 | 26-7-2023 | 26-07-23 9:12 PM | 26-07-23 10:16 PM | 18,6 |
| 2 | 30-7-2023 | 30-07-23 8:10 AM | 30-07-23 9:42 AM | 14,1 |
| 2 | 30-7-2023 | 30-07-23 10:24 AM | 30-07-23 11:44 AM | 7,4 |
| 2 | 30-7-2023 | 30-07-23 1:00 PM | 30-07-23 1:17 PM | 0,7 |
| 2 | 30-7-2023 | 30-07-23 1:19 PM | 30-07-23 2:27 PM | 4,4 |
| 2 | 30-7-2023 | 30-07-23 2:45 PM | 30-07-23 2:58 PM | 3,8 |
| 2 | 30-7-2023 | 30-07-23 3:19 PM | 30-07-23 3:50 PM | 4,1 |
I want to create a table that tracks the days that the car is used and the availability.
- The start date per car can be different based on de MIN(date) of every car
- The end date per car is the same and is the MAX(date) of all the cars.
The end goal is to create a table like below:
| CarNr | Date | Used | Available |
| 1 | 25-7-2023 | 1 | 1 |
| 1 | 26-7-2023 | 1 | |
| 1 | 27-7-2023 | 1 | |
| 1 | 28-7-2023 | 1 | 1 |
| 1 | 29-7-2023 | 1 | |
| 1 | 30-7-2023 | 1 | 1 |
| 1 | 31-7-2023 | 1 | |
| 1 | 1-8-2023 | 1 | 1 |
| 2 | 26-7-2023 | 1 | 1 |
| 2 | 27-7-2023 | 1 | |
| 2 | 28-7-2023 | 1 | |
| 2 | 29-7-2023 | 1 | |
| 2 | 30-7-2023 | 1 | 1 |
| 2 | 31-7-2023 | 1 | |
| 2 | 1-8-2023 | 1 |
- Anonymous3 years ago
Hi Anonymous ,
Here are the steps you can follow:
1. Create calculated table.
Table2 = var _table1={1} var _table1date= CALENDAR( MINX(FILTER(ALL('Table'),'Table'[CarNr]=1),[Date]), MAXX(ALL('Table'),'Table'[Date])) var _table2={2} var _table2date= CALENDAR( MINX(FILTER(ALL('Table'),'Table'[CarNr]=2),[Date]), MAXX(ALL('Table'),'Table'[Date])) return UNION( CROSSJOIN( _table1,_table1date) , CROSSJOIN( _table2,_table2date))2. Create calculated column.
Used = var _value= MAXX( FILTER(ALL('Table'), 'Table'[CarNr]=EARLIER('Table2'[Value])&&'Table'[Date]=EARLIER('Table2'[Date])),[Distance]) return IF( _value=BLANK(),BLANK(),1)Available = var _mindate=MINX(FILTER(ALL('Table'),'Table'[CarNr]=EARLIER('Table2'[Value])),[Date]) return IF( 'Table2'[Date]>=_mindate&&'Table2'[Date]<=MAXX(ALL('Table'),'Table'[Date]),1,0)3. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
1 Reply
- AnonymousNot applicable
Hi Anonymous ,
Here are the steps you can follow:
1. Create calculated table.
Table2 = var _table1={1} var _table1date= CALENDAR( MINX(FILTER(ALL('Table'),'Table'[CarNr]=1),[Date]), MAXX(ALL('Table'),'Table'[Date])) var _table2={2} var _table2date= CALENDAR( MINX(FILTER(ALL('Table'),'Table'[CarNr]=2),[Date]), MAXX(ALL('Table'),'Table'[Date])) return UNION( CROSSJOIN( _table1,_table1date) , CROSSJOIN( _table2,_table2date))2. Create calculated column.
Used = var _value= MAXX( FILTER(ALL('Table'), 'Table'[CarNr]=EARLIER('Table2'[Value])&&'Table'[Date]=EARLIER('Table2'[Date])),[Distance]) return IF( _value=BLANK(),BLANK(),1)Available = var _mindate=MINX(FILTER(ALL('Table'),'Table'[CarNr]=EARLIER('Table2'[Value])),[Date]) return IF( 'Table2'[Date]>=_mindate&&'Table2'[Date]<=MAXX(ALL('Table'),'Table'[Date]),1,0)3. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly