Introduction to BrewwQL

What is BrewwQL?

We designed BrewwQL to help users simply and powerfully filter their data in Breww.

With a few simple operators, you can now easily create simple or complex filters to drill down deeper and more easily into your Breww data.

BrewwQL can seem daunting at first, especially if you’re new to “query languages”, but the doors it opens to both reporting and customisability in Breww make it worth reading on! If you’ve built reporting using SQL before, then you’ll be right at home.

Examples

Basic examples

To best understand BrewwQL, it’s helpful to see some simple examples.

Let’s say we wanted to see all of our customers whose delivery address was in London. In the customer filter form, we would type:

delivery_address_city = "London"

And that’s it. The autocomplete will show every option as you go, making it really straightforward to put together queries and view available options.

If we want to drill down deeper, we can. From those customers, maybe we only want to see those whose average order value is greater than £250. For this we would chain two statements together with the and operator.

delivery_address_city = "London" and average_order_value > 250

Perhaps we are wondering which of those customers have lapsed, as we might want to contact them about reordering. So let’s narrow the search for only customers who haven’t ordered in the last 90 days.

delivery_address_city = "London" and average_order_value > 250 and last_order_date < "90 days ago"

Now let’s say we are doing some admin, and we wanted to see all customers who we haven’t entered a contact for yet. In the customer filter box, we would type:

contacts = None

Advanced examples

BrewwQL allows us to traverse through attributes of what we are searching through. For example if we wanted to see customers who are part of a customer group with a billing address in London we would write:

customer_group.invoice_address_city = "London"

The . between customer_group and invoice_address_city is used in BrewwQL as a way of traversing through attributes of attributes.

We can also use brackets to add more complexity to our searches.

(delivery_address_city = "London" or average_order_value > 250) and last_order_date < "90 days ago"

The above statement will be analysed from left to right, and statements in brackets will be evaluated as a single attribute. So the query will retrieve all customers whose delivery address city is London OR who has an average order value greater than £250 ONLY if they also have a last order date more recent than 90 days ago.

We can also nest brackets within brackets. The below query will return either customers who are in London AND are Pubs, OR those whose average order value is greater than £250, as long as their last order date is more recent than 90 days ago.

((delivery_address_city = "London" and type.type = "Pub") or average_order_value > 250) and last_order_date < "90 days ago"

Using the same attribute multiple times

This can be a little confusing at first. Each statement between operators, must be complete and be able to work on its own. This means that if you’re joining multiple filters together with and or or, like STATEMENT and STATEMENT, both statements must be complete on their own.

We’ll walk through an example - when looking at product filtering, you could filter the type of product to only include casks with:

type = "Cask"

Or you could filter kegs only with:

type = "Keg"

Now, if you wanted to include both casks and kegs, you might be tempted (and understandably so), to do this:

type = "Cask" and "Keg"

However this is incorrect on two counts. The first being that each statement (each side of the and) must be a complete statement. Here, the type = "Cask" is perfect, but the second statement being just "Keg" is meaningless on its own, and so will not work. So, you can correct this to:

type = "Cask" and type = "Keg"

This is much closer (and hopefully explains what’s meant by each statement being a complete statement when looked at on its own). However, in this particular case this isn’t what’s needed. We’re looking for both cask and keg products, but this will be checked against each individual product, and any single product cannot be both a cask and a keg. The above is filtering on products which are both casks and kegs (which is impossible), so what we really need to check is if the product is either a cask or the product is a keg. And that can be done with:

type = "Cask" or type = "Keg"

Success! The above would give the desired result or finding both cask products and keg products. If you wanted to make this a little neater (and maybe more readable), you could instead use the in operator to check if the product’s type is in the list of options given. This would be done with:

type in ("Cask", "Keg")

This is certainly more readable if the number of options was to increase from two to four (or even more):

type in ("Cask", "Keg", "Service", "Guest beer")

verses the more verbose:

type = "Cask" or type = "Keg" or type = "Service" or type = "Guest beer"

Dates

BrewwQL allows you to filter on dates, and has a powerful natural language understanding. For example, if you’d like all customers who have ordered since the 1st January 2021, you can simply enter:

last_order_date > "1st January 2021"

or:

last_order_date > "01/01/2021"

or even:

last_order_date > "1 Jan 2021"

BrewwQL also understands relative dates, so you can filter on the last 30 days with:

last_order_date > "30 days ago"

or filter on the last two months with:

last_order_date > "2 months ago"

Some other useful options for date filtering include the phrases:

last_order_date > "first of this month"
last_order_date < "last of this month"
last_order_date > "first of last month"
last_order_date < "last of last month"
last_order_date < "Monday last week"
last_order_date < "Monday next week"
last_order_date < "last Monday"
last_order_date < "previous Monday"
last_order_date < "next Tuesday"
last_order_date < "this Wednesday"

A date is greater > than another if it is more recent, and less < than another if it is older.

You can think of this as if someone started counting at the beginning of time. The number they had counted to last week is less than the number they have counted to right now.

To filter on a range of dates, you can use the same field twice:

last_order_date > "first of last month" and last_order_date  <= "last of last month"

Case-sensitivity

Do capitals matter in my searches? No, a search for:

delivery_address_city = "London"

and

delivery_address_city = "london"

will return the same results.

Operator reference

Operator Meaning Example Verbose
= Equal to name = "The Shop" Where the name is equal to “The Shop”
!= Not equal to name != "The Shop" Where the name is not equal to “The Shop”
~ Contains name ~ "The" Where the name contains “The”
!~ Does not contain name !~ "The" Where the name does not contain “The”
> Greater than average_order_value > 100 Where the average order value is greater than 100
>= Greater than or equal to average_order_value >= 100 Where the average order value is greater than or equal to 100
< Less than average_order_value < 100 Where the average order value is less than 100
<= Less than or equal to average_order_value <= 100 Where the average order value is less than or equal to 100
in In name in ("The Shop", "The Pub", "The Restaurant") Where the name is either “The Shop” or “The Pub” or “The Restaurant”
not in Not in name not in ("The Shop", "The Pub", "The Restaurant") Where the name is not “The Shop” and not “The Pub” and not “The Restaurant”
1 Like

do you have a spreadsheet of all QL commands and their functions at all?

1 Like

The guide above shows all the comparison operators (e.g. equals, less than) and how to use BrewwQL. When writing BrewwQL into a BrewwQL input box within Breww, you’ll be shown all the possible fields that can be filtered upon (such as customer name or invoice date).

We don’t intend to create a spreadsheet of these fields, as the possible fields evolves over time, and a spreadsheet version of them would become out of date quickly and hard for us to maintain.

Can we export these reports as a .csv?

Which reports are you hoping to export? If it’s a Data Explorer report, there’s a field at the top where you can change the ‘Output’ from on-screen to export to Excel.