10 Replies Latest reply on Apr 10, 2017 8:33 PM by MinaSalama

    AF Analyses expression with table lookup


      When creating an AF Analyses is there a way I can perform a table lookup? I need to bring a value from PI and use that value to find another value in a look up table. The value that was returned from the lookup needs to be written to another tag in PI. It seems like a fairly simple process, I could easily be glazing over an Analysis function that does this.

        • Re: AF Analyses expression with table lookup

          Hi Alan,


          Yes, it could be achieved.


          Here are 2 attribute in PI AF server, A, B.


          A: get the value from PI server


          B: get the value from table lookup


          Please see my example following.  However, my B has no result, as I just use some Random point(cdt158) in PI Server to do this example.


          setting for Attribute A:












          Setting for Attribute B:






          Then, I believe you wish to insert the value of Attribute B to another PI point.  This time, we need a piece of code.  At the first, let me suppose you have the PI Point, named "test", to receive the value.



          PISystems af_sdk = new PISystems();
          PISystem af_server = af_sdk["WIN-91UTM7K1LDQ"];       // connect AF server
          AFAttribute attribute = af_server.Databases["test"].Elements["Element1"].Attributes["B"];  // get the attribute B
          AFTime time = new AFTime("*");
          AFValue value = attribute.GetValue(time);      // get the value of attribute B
          PIServers servers = new PIServers();
          PIServer server = servers["WIN-91UTM7K1LDQ"];   // connect PI server
          PIPoint point = PIPoint.FindPIPoint(server, "test");  // update B's value to "test"
          point.UpdateValue(value, AFUpdateOption.Insert);

           Wish this could help.


          Xi Wang


          vCampus team

            • Re: AF Analyses expression with table lookup

              Thank you for the response Xi Wang. I was able to figure out how to get the value into AF and how to use that value to lookup another value (attributes A & B in your example). The part I'm having difficulty is getting the value back into a PI Tag. If it were my choice I would implement the code you have above, but I am trying to do this without implementing any custom code. The secondary requirement is the data needs to be backfillable into PI. Is there any such solution that can accomplish this? I believe I've gotten close by using AF Analyses.

                • Re: AF Analyses expression with table lookup

                  Looks like I got it to work. It requires 4 AF Attributes; the output tag, the input tag, a corrected tag (possibly not necessary), and a tag to hold the new value.


                  The corrected tag removes any erroneous data from the input tag. In my case I had a few "Shutdown" states in my sinusoid data. These system digital states seemed to break the AF Analyses backfill process. The corrected tag just provides a temporary value in it's place.


                  The attribute holding the new value uses the corrected value and the Table Lookup DR to get the new value.


                  Finally the data from the Table lookup is sent to an output tag via an AF Analyses. The data can also be backfilled.

                    • Re: AF Analyses expression with table lookup
                      Mike Zboray



                      As you've discovered, there's no way to do a direct lookup on an AF Table in an Analysis. You have to use Table DR. As for the "Shutdown" state breaking backfill. That sounds like a bug. I wasn't able to reproduce it using a simple analysis with one PI Point input and one PI Point output. If you could clarify (what exactly do you mean by broken?) and give a more detailed description of what you've got that would help reproduce the problem.