Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

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:

 

CarNrDateStartDate/TimeEndDate/TimeDistance
125-7-202325-07-23 7:20 AM25-07-23 7:24 AM0,1
125-7-202325-07-23 12:00 PM25-07-23 12:25 PM15
125-7-202325-07-23 1:18 PM25-07-23 1:53 PM15
125-7-202325-07-23 4:25 PM25-07-23 4:26 PM0,1
128-7-202328-07-23 7:12 AM28-07-23 9:46 AM19,8
128-7-202328-07-23 9:50 AM28-07-23 9:51 AM0,2
128-7-202328-07-23 2:09 PM28-07-23 2:25 PM8,9
128-7-202328-07-23 2:41 PM28-07-23 2:44 PM0,2
130-7-202330-07-23 8:57 AM30-07-23 9:20 AM5,4
130-7-202330-07-23 9:30 AM30-07-23 9:48 AM5,6
11-8-202330-07-23 9:57 AM30-07-23 9:59 AM0,2
226-7-202326-07-23 9:10 AM26-07-23 9:28 AM0,5
226-7-202326-07-23 9:28 AM26-07-23 9:32 AM0,8
226-7-202326-07-23 7:39 PM26-07-23 8:13 PM8,4
226-7-202326-07-23 8:22 PM26-07-23 8:43 PM8,9
226-7-202326-07-23 9:11 PM26-07-23 9:11 PM0
226-7-202326-07-23 9:12 PM26-07-23 10:16 PM18,6
230-7-202330-07-23 8:10 AM30-07-23 9:42 AM14,1
230-7-202330-07-23 10:24 AM30-07-23 11:44 AM7,4
230-7-202330-07-23 1:00 PM30-07-23 1:17 PM0,7
230-7-202330-07-23 1:19 PM30-07-23 2:27 PM4,4
230-7-202330-07-23 2:45 PM30-07-23 2:58 PM3,8
230-7-202330-07-23 3:19 PM30-07-23 3:50 PM4,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: 

 

CarNrDate Used  Available 
125-7-2023                1                        1
126-7-2023                         1
127-7-2023                         1
128-7-2023                1                        1
129-7-2023                         1
130-7-2023                1                        1
131-7-2023                         1
11-8-2023                1                        1
226-7-2023                1                        1
227-7-2023                         1
228-7-2023                         1
229-7-2023                         1
230-7-2023                1                        1
231-7-2023                         1
21-8-2023                         1

 

  • Anonymous's avatar
    Anonymous
    3 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

  • Anonymous's avatar
    Anonymous
    Not 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