P# Coding Rules And Style Guidelines

Logic / Workflow Code

The coding rules and style guidelines detailed here apply to scripts that are not used to pull data into PBI only. Guidelines for P# code used to pull data into PBI are captured in the section Visualization Code.

Comments

  • comment tables and columns if the purpose is not obvious
  • insert a header describing the script (right-click inside of script and select "Insert header")

Coding Rules

Utilize the auto formatting feature by right-clicking inside the script and selecting "Auto Format" to properly format P# scripts.

  • max line width 80 columns (unless screen readability is severely affected)
  • use tabs to indent code (1 tab per level)
  • use brackets () to structure column definitions
  • don't mix static and dynamic tables
  • use pascal casing when calling functions
  • use pascal casing when using operators (Or, And)
  • always place a single space around operators and assignments (+, -, !+, !-, *, /, =)
  • always place operators at the end of a line and indent the following statement if the line would exceed the max width
  • separate function arguments with a single space
  • use new line and indentation if function arguments would exceed the max width, place closing bracket at the same indentation level as the function name
  • if a table references more than one input column place the input statement on a new line and indent it with one tab. Place every input table name on a separate line
  • use snippets to avoid code duplicates
  • use IIf() only for nested statements

Examples:

Table "Calculations" Input "Input 1"
    Column "Gapfilled Water" in "m3"
        FillGaps("produced water per time increment" in "m3", "linear")
    End Column

    Column "WOR" in " "
        Column "Gapfilled Water" in "m3" /
            "produced oil per time increment" in "m3"
    End Column
End Table

Table "Calculations 2"
    Input "Input 1"
        "Input 2"
        "Input 3"
        "Input 4"
       
    Column "Well Head Pressure Upper Threshold" in "bar"
        If IsNotNull("well head pressure upper threshold" in "bar") Then
            "well head pressure upper threshold" in "bar"
        Else
            If IsNotNull(
                ValueFromParent("well head pressure upper threshold" in "bar",
                    "Layer",
                    "Reservoir Hierarchy"
            )
        )
            Then
                ValueFromParent("well head pressure upper threshold" in "bar",
                    "Layer",
                    "Reservoir Hierarchy"
                )
            Else
                ValueFromParent("well head pressure upper threshold" in "bar",
                    "Field",
                    "Reservoir Hierarchy"
                )
            End If
        End If
    End Column
End Table

Visualization Code

For P# code purely used to pull data into PBI some additional special guidelines apply. Those are detailed here. If in conflict with the rules and guidelines stated above, the rules and guidelines stated in this section supersede the above.

Script / Pivot Table Names

  • The name of the script or Pivot Table used to pull data to PBI has to clearly mark it as such. The preferred nomenclature is:

    Package Name + Visualization - Additional Information [optional]

    Examples:
      Chan Plot Visualization
      Production And Completion Dashboards Visualization - Static Data

Column Names

  • Use short column names. For abbreviations see the list of standardized abbreviations below
  • If it is not obvious which data a column contains, place a comment directly above the column
Example:
Table "ABC Plots"
    // x-axis
    Column "Water" in " "
        "abc water ratio" in " "
    End Column
 
    // y-axis
    Column "Oil" in " "
        "abc oil ratio" in " "
    End Column
End Table

Round Columns

Use the  Round() function in P# code used purely for visualization (and in Pivot Tables) as it helps to reduce the amount of data digested by PowerBI. The performance of PowerBI improves significantly with decreasing the amount of digested data.
Example:
Table "Scores"
    Column "Production Score" in " "
      Round("production score" in " ", 3)
    End Column
 
    Column "Problem Score" in " "
      Round("problem score" in " ", 3)
    End Column
 
    Column "Reservoir Score" in " "
      Round("reservoir score" in " ", 3)
    End Column
End Table

Standardized Abbreviations

  • latitude -> Lat
  • longitude -> Long
  • lateral length -> Lat Length
  • condensate -> Cond
  • operating expense -> OpEx
  • capital expense -> CapEx
  • cash flow -> Cash Flow
  • oil equivalent -> BOE (for daily rate please also use BOE in P# column name and replace it with BOE/d on the dashboard)
  • natural gas equivalent -> NGE (for daily rate please also use NGE in P# column name and replace it with NGE/d on the dashboard)
  • Average -> Avg
  • Total -> Ttl
  • Horizontal -> Horz
  • Vertical -> Vert
  • Bottom Hole -> BH
  • Best 90 days or Best 3 months -> B90d or B3m
  • produced oil per time increment  -> Oil 
  • produced water per time increment -> Water
  • produced gas per time increment -> Gas
  • injected water per time increment -> Water Injected
  • injected gas per time increment -> Gas Injected
  • produced oil per time increment forecast -> Oil Forecast
  • produced water per time increment -> Water Forecast
  • produced gas per time increment -> Gas Forecast