# Introducing Expressions in GraphQL Queries

**URL:** https://community.bitquery.io/t/introducing-expressions-in-graphql-queries/1322
**Category:** GraphQL Tutorials
**Created:** [January 4, 2023, 5:58am UTC](https://community.bitquery.io/t/introducing-expressions-in-graphql-queries/1322 "2023-01-04T05:58:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Divya](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@Divya](https://community.bitquery.io/u/Divya)
#### Post date: [January 4, 2023, 5:58am UTC](https://community.bitquery.io/t/introducing-expressions-in-graphql-queries/1322/1 "2023-01-04T05:58:50Z")

</div>

One of the [core missions of Bitquery](https://bitquery.io/blog/blockchain-intelligence-system) is to provide better accessibility to blockchain data. Therefore [we choose GraphQL](https://bitquery.io/blog/blockchain-graphql) to provide control to developers pulling data through our APIs.

We continue to make the GraphQL interface more powerful and today we introduce the support for “Expressions” in GraphQL APIs.

## What is an Expression?

Expression will allow users to apply essential mathematical functions (like subtract, multiply, sum, divide) in the queries themselves. However, expression can only be applied to metrics. To learn more about metrics, please read our article explaining [Bitquery query architecture](https://bitquery.io/blog/blockchain-intelligence-system).

Note: There is no standard definition of metrics, but a simple rule of thumb is Metics have a “calculate” field.

 ![](https://us1.discourse-cdn.com/flex016/uploads/bitquery/original/1X/5499ab00bbc30ac206b0f87007db04beb20c6834.png)

## Breaking down Expressions

Check out the following query.

```auto
query GetTopGainers {
  ethereum(network: bsc) {
    dexTrades(
      options: {desc: ["baseCurrency.name", "amount_expression"], limit: 50, limitBy: {each: "buyCurrency.name, a.b", limit: 2}}
      quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      time: {since: "2022-12-01"}
      tradeAmountUsd: {gt: 10}
    ) {
      baseCurrency {
        name
        address
        symbol
      }
      tradeAmount(in: USD)
      open_price: minimum(of: block, get: quote_price)
      close_price: maximum(of: block, get: quote_price)
      buyAmount
      sellAmount
      price_expression: expression(get: "close_price / open_price")
      Price_expressionX2: expression(get: "price_expression * 2")
      open_price_x2: expression(get: "open_price * 2")
      amount_expression: expression(get: "buyAmount - sellAmount")
      buyCurrency {
        address
        name
      }
      a: sellCurrency {
        b: address
      }
    }
  }
}

```

Now in the above query, you can see the following line

`price_expression: expression(get: "close_price / open_price")`

Here, we are getting “open\_price” and “close\_price” and then dividing “close\_price” from “open\_price” using “expression”.

Let’s see another example

```auto
{
  ethereum {
    transactions {
      gasValue(calculate: sum)
      coun2x: expression(get: "gasValue * 2")
    }
  }
}

```

Here you can see how we are multiplying `gasValue` with 2.

### Allowing more than 1 field in `limitby`

If you want to limit results per specific field, you can use [limitby](https://bitquery.io/blog/conditional-aggregation). Now we have added support for more than 1 field in limitby field.

Look at the below example where we have used both buyCurrency.address, sellCurrency.address in the limitBy field. ([query URL](https://graphql.bitquery.io/ide/limit-by-example-with-more-than-1-field))

```auto
{
ethereum(network: ethereum) {
dexTrades(
options: {desc: ["block.height", "tradeIndex"],
limit: 10, offset: 0,
limitBy: {each: "buyCurrency.address,sellCurrency.address", limit: 1}}
date: {since: "2022-12-27", till: "2023-01-03"}
) {
block {
timestamp {
time(format: "%Y-%m-%d %H:%M:%S")
}
height
}
tradeIndex
protocol
exchange {
fullName
}
smartContract {
address {
address
annotation
}
}
buyAmount
buyCurrency {
address
symbol
}
buy_amount_usd: buyAmount(in: USD)
sellAmount
sellCurrency {
address
symbol
}
sell_amount_usd: sellAmount(in: USD)
transaction {
hash
}
}
}
}

```

If you have any questions about our products, ask them on our [Discord](https://discord.gg/EEBVTQnb2E) and [Telegram channel](https://t.me/Bloxy_info) or email us at [support@bitquery.io](mailto:support@bitquery.io).

---

<div class="post-metadata">

### Author: ![TaxiDriver](https://sea2.discourse-cdn.com/flex016/user_avatar/community.bitquery.io/taxidriver/32/798_2.png) [@TaxiDriver](https://community.bitquery.io/u/TaxiDriver)
#### Post date: [August 23, 2023, 5:38pm UTC](https://community.bitquery.io/t/introducing-expressions-in-graphql-queries/1322/2 "2023-08-23T17:38:50Z")

</div>

Hello there  
I need help fix token liquidity and calls and more action  
i staked in my tron wallet before three years many token and coins and there is a lot of action to do: sign in, approve, update token info and more  
I hade crashing with my car and didnt sign in for long time How can I fix all of this pls  
I will pay you if you help me fix this case  
thanks

 ![Screenshot from 2023-08-23 13-31-17](https://us1.discourse-cdn.com/flex016/uploads/bitquery/original/1X/b1f18a40e72120c1229fe812af2673ce0acb20e4.png)
