Forum Discussion

stuarthokie's avatar
stuarthokie
Frequent Visitor
2 years ago

Native Query to Pivot Large Volumes of Data

Hello!  I have a challenge for which I have not seen a resolution posted.  I have seen similar issues resolved, but none like what seems to be my normal challenge.  I am green to the more complex workings of PBI and am therefore seeking help.

 

I would like to pivot my data.  But I have restrictions that make it so column pivoting is off of the table as an option for resolution.  If possible, I would like this to occur in the Native Query.  This seems to be the best option but please correct me if I am wrong.

 

DATA TABLE EXAMPLE:

The "PLC Tag" names are in the same column, this is a problem

Time StampPLC TagValue
5/3/24 2:51Tag15.00
5/3/24 2:51Tag210.02
5/3/24 2:51Tag315.03
5/3/24 2:52Tag120.05
5/3/24 2:52Tag225.07
5/3/24 2:52Tag330.08
5/3/24 2:53Tag135.10
5/3/24 2:53Tag240.12
5/3/24 2:53Tag345.13
5/3/24 2:54Tag150.15
5/3/24 2:54Tag255.17
5/3/24 2:54Tag360.18
5/3/24 2:55Tag165.20
5/3/24 2:55Tag270.22
5/3/24 2:55Tag375.23
5/3/24 2:56Tag180.25
5/3/24 2:56Tag285.27
5/3/24 2:56Tag390.28
5/3/24 2:57Tag195.30
5/3/24 2:57Tag2100.32
5/3/24 2:57Tag3105.33
5/3/24 2:58Tag1110.35
5/3/24 2:58Tag2115.37
5/3/24 2:58Tag3120.38

 

DESIRED OUTPUT EXAMPLE:

1: The "PLC Tag" names become the headers of different columns for each unique "PLC Tag" (NOTE: there will be MANY more than 3 in this example)
2: Each row is defined by each unique Time Stamp (yes, the various tags' data have identical time stamps and are minute data)
3: The Values are placed in the proper "PLC Tag" and "Time Stamp" intersection

Time StampTag1Tag2Tag3
5/3/24 2:515.0010.0215.03
5/3/24 2:5220.0525.0730.08
5/3/24 2:5335.1040.1245.13
5/3/24 2:5450.1555.1760.18
5/3/24 2:5565.2070.2275.23
5/3/24 2:5680.2585.2790.28
5/3/24 2:5795.30100.32105.33
5/3/24 2:58110.35115.37120.38

NOTE: I believe achieving this using a Native, Folded Query is the goal due to processing concerns. Pivoting the data on the back end is a non-workable option due to tens of millions of rows of data and counting. Pivoting either crashes my machine or takes several hours to refresh if successfull. The data are so many that Incremental Refreshing will also be employed each day, multiple times per day, as the data table grows.

 

NOTE: Achieving this is NOT how it will end up looking in the visual; this is only step 1: desired organization of data. There will be MANY new columns of calculated metrics created that will have somewhat complicated expressions incorporating one, some, or MANY of the "PLC Tags'" values.

 

 

12 Replies

  • Your data is already in the perfect format for ingestion. Resist the urge to mess with it, and do all your pivoting in the visuals.

    • stuarthokie's avatar
      stuarthokie
      Frequent Visitor

      Thx, Ibendlin!  The desired result shown is not at all what my visuals will look like, only what the resulting table will look like.  In fact, there are exactly zero items from either the original or the resulting table that will be a part of the visuals: no time stamps, no "Tag Names", no values.

       

      This challenge is to get the data in a desired format in order to reduce processing on the back end so that I may add many new columns of calculated metrics created that will have somewhat complicated expressions incorporating one, some, or MANY of the "PLC Tags'" values.  It is these new calculated metrics which will be shown in the visuals.

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        Put your data into a matrix table, then examine the DAX query that Power BI creates for that (including filters).  Use that query as the basis for your measure calculations.