# How to Connect Your Spreadsheet

If you use spreadsheets to monitor trading activity, you can connect them to Molecule via our API. This will save a lot of time as it removes the tedium of updating your file and automates the process. You can use one of our sample files (available by emailing [support@molecule.io](https://help.molecule.io/article/support@molecule.io)), start one from scratch. Connect your existing spreadsheet using the instructions below. This article assumes you are using **Excel 2016**.

* On your spreadsheet, select a designated cell where you would like to input an As-Of date to refresh the values on the spreadsheet. Change the label of this cell to **as\_of** in the top left text box underneath **File**. Populate this cell with a date value for now (ex: 12/10/2017)

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265008864/file-3-edg-rt-synh.png" alt="" width="563"><figcaption></figcaption></figure>

* Click on **Data** < **From Web** (Under **Get & Transform Data**):

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265009132/file-juju-v-4-ajz-f.png" alt="" width="563"><figcaption></figcaption></figure>

* A pop-up will appear asking for a URL:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265009404/file-w-ga-nyxz-d-2-b.png" alt="" width="563"><figcaption></figcaption></figure>

* From your Molecule account, click on **REPORTS** < **EXTRACTS**
* Under **P\&L,** check the summary box and click on the copy icon, highlighted red below (if you would like the complete version of the P\&L extract, leave the summary box unchecked):

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265009659/file-2-vd-mub-8-py-u.png" alt="" width="563"><figcaption></figcaption></figure>

* Paste the URL into the excel pop-up and click **OK.**
* A pop-up will appear titled **Access Web Content**. Click on **Basic** on the left pane of the pop-up and enter your Molecule credentials
  * The username is the email address you use to sign into Molecule
  * Password will be your token from Molecule
    * To access click **Settings** < **API Key**&#x20;
    * If you still need to, generate a token&#x20;
    * You also can revoke and generate a new one if you have lost your token
* Then click **Connect**:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265009910/file-x-691-xpuwh.png" alt="" width="563"><figcaption></figcaption></figure>

* A new pop-up will appear showing your trade details, then click **Load.**
* Your P\&L extract will now be loaded to a new tab in the spreadsheet, and a pane titled **Queries & Connections** will appear on the right:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265010178/file-45-z-fmi-37-rx.png" alt="" width="563"><figcaption></figcaption></figure>

* Right-click on **monthly\_valuations** under **Queries & Connections** and select **Edit** to open the Query Editor in a separate window
* Click on **Queries** (highlighted red) at the top of the left pane:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265010545/file-ot-9-adzw-9-n-u.png" alt="" width="188"><figcaption></figcaption></figure>

* Right-click on **monthly\_valuations** and rename it to **Molecule Query**. Right-click on **Molecule Query** once more and select **Advanced Editor**:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265010813/file-2-b-0-ri-1-t-odr.png" alt="" width="563"><figcaption></figcaption></figure>

* Remove the existing query in the **Advanced Editor** and copy/paste the following query:

```
let
    Datey = GetValue("as_of"),
    Url = "https://app.molecule.io/monthly_valuations.csv?show_aggregated=false&as_of=" 
        & Datey &"&summary=true",
    Source = Csv.Document(Web.Contents(Url),[Delimiter=",", Columns=20, Encoding=1252, 
        QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(Source),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"account", type text}, 
        {"as_of", type date}, {"book", type text}, {"counterparty", type text}, {"direction", type text}, 
        {"product_code", type text}, {"contract_start", type date}, {"call_put", type text}, 
        {"strike", type text}, {"position", Int64.Type}, {"delta", Int64.Type}, {"mtm_change", type number}, 
        {"base_currency_mtm_change", type number}, {"curve_price", type number}, 
        {"prior_curve_price", type number}, {"deal_type", type text}, {"frequency", type text}, 
        {"realization_date", type date}, {"status", type text}, {"explanation", type text}})
in
    #"Changed Type"
```

* \*NOTE\*: If you copied the link for the complete P\&L extract, use the query below:
* Select **Done** on the Advanced Editor window where you pasted the query. You will receive an **Expression Error** - this is expected.
* Right-click on **Molecule Query** on the same left pane and select **Duplicate.** You will now see a second query populate on the left pane titled, **Molecule Query(2)**:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265011145/file-pici-hv-3-qh-8.png" alt="" width="563"><figcaption></figcaption></figure>

* Right-click on **Molecule Query (2)** and rename it to **GetValue**. Right-click on **GetValue** once more and select **Advanced Editor.** Remove the existing query, copy/paste the following query and select **Done**:

```
let GetValue=(rangeName) => 
    let
      name = Excel.CurrentWorkbook(){[Name=rangeName]}[Content],
      value = name{0}[Column1]
    in
      DateTime.ToText(value, "yyyy-MM-dd")
    in GetValue
```

* You should see a field appear that says **Enter Parameter** - you can just ignore this.

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265011384/file-sikksh-9-rj.png" alt="" width="563"><figcaption></figcaption></figure>

* When you single-click on **Molecule Query**, you should now see a notification that says: "**Information is required about data privacy**:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265011681/file-b-8-bv-24-u-6-f-1.png" alt="" width="563"><figcaption></figcaption></figure>

* Select **Continue.**&#x20;
* You should see a pop-up titled **Privacy Levels**:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265011931/file-ff-t-86-r-k-8-j-m.png" alt="" width="563"><figcaption></figcaption></figure>

* Click on the drop-down menu in the pop-up next to **Current Workbook** and select **Public**. (This means public to your company only). Click on the drop-down menu right underneath, next to <https://app.molecule.io/>, and select **Public**. Then select **Save**.
* You should now see a table show up under **Molecule Query**:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265012203/file-y-yprz-lgxac.png" alt="" width="563"><figcaption></figcaption></figure>

* Select "Close & Load" on the top left corner:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265012481/file-z-lg-9-qp-cp-3-d.png" alt="" width="563"><figcaption></figcaption></figure>

**Note:** You can now update your designated as\_of field to any as\_of date you'd like to see your values for, and then click on **Refresh All** under the data tab:

<figure><img src="https://files.helpdocs.io/56bu62syz9/articles/90c1dosmnt/1689265012754/file-2-d-0-gcfl-ir.png" alt="" width="563"><figcaption></figcaption></figure>

The data will now load in a new tab on your spreadsheet. You can pivot to see things how you would like. You can also use Excel formulas to calculate metrics, such as position and P\&L, that will refresh based on the as-of date value you used. The spreadsheet can be set up to refresh automatically in a given interval as well. You are not limited to using just the P\&L extract. You can use the curves extract to have your market data reflected on your spreadsheet, for example. The possibilities are endless! If you have any questions, please send them our way at <support@molecule.io>.

<br>
