Forum Discussion

dariva's avatar
dariva
Regular Visitor
6 years ago

Question about pivoting timeseries

I am trying to do the following. 

I have a database that have a timeserie like this:

datetagsvalue
01/03/2020tag11
02/03/2020tag12
03/03/2020tag13
01/03/2020tag23.4
02/03/2020tag21.2
03/03/2020tag23.5

When I performa a pivot operation in this table I get this

 tag1tag2
01/03/20201 
01/03/2020 3.4
02/03/20202 
02/03/2020 1.2
03/03/20203 
03/03/2020 3.5

Is there any way to make the time combine the time column in a way that I have something like this

 tag1tag2
01/03/202013.4
02/03/202021.2
03/03/202033.5

I want this because I want to perform some calculation using the values in the same timestamps.

 

Regards,

 

4 Replies

  • dariva's avatar
    dariva
    Regular Visitor

    Hi,

     

    I did a test with this dummy data and I managed to do what I want by performina "GROUP BY" operation before doing the pivotation. Nevertheless when I do the same with the real data I receive the following message.

    Expression.Error: The field 'X.PV' already exists in the record.
    Details:
    Name=X.PV
    Value=

    However if I do the same using a Tag_ID columnn (a unique identifier for each tag) it work! Does anayone have a clue about what could be happening?

     

    Regards,

     

      • dariva's avatar
        dariva
        Regular Visitor
         

         amitchandak v-qiuyu-msft

         

        After I post the question I tried this operation with this mock data I presented. But whit the actual data I am having some weird behavior. I think it worth trying to explain it.

         

        1) In the original dataset I have one entry every minute for each tag and each tag has as numerical (int) ID. If I use the ID instead of the tag the pivoting works perfectly. But using the tag (string) I receive that error message I show. 

        2) Doing some test I found the following. If I filter the time column in the data table to keep just some minutes the pivoting using the tag works! I increased the amount of time until I reached a limit of 55 minutes (+/-) when the problem start happening.

         

        Finally I manage to obtain my desired result in a not very elegant way. I did the following.


        1) I pivoted the data table in the using the time column 

        2) I unpivoited the previous pivoted table

        3) I them pivoted the previous unpivoted table using the tag column! (and it worked!!!).

         

        Regards,

         

         

  • If the data type is number. You can use sum or max to group it in a matrix