bigfunctions > format_percentage
format_percentage¶
Call or Deploy format_percentage
?
✅ You can call this format_percentage
bigfunction directly from your Google Cloud Project (no install required).
- This
format_percentage
function is deployed inbigfunctions
GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error). - Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework
Public BigFunctions Datasets:
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Description¶
Signature
format_percentage(first_number, second_number, nb_decimals)
Description
Return first_number / second_number
as a formatted percentage
in a user-friendly format. You can use this function
to handle a safe divide of the two numbers as well as your desired level of rounding.
Examples¶
select bigfunctions.eu.format_percentage(1, 3, 2)
select bigfunctions.us.format_percentage(1, 3, 2)
select bigfunctions.europe_west1.format_percentage(1, 3, 2)
+----------------------+
| formatted_percentage |
+----------------------+
| 33.33 % |
+----------------------+
Need help using format_percentage
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using format_percentage
?
If the function does not work as expected, please
- report a bug so that it can be improved.
- or open the discussion with the community on Slack.
For professional suppport, don't hesitate to chat with us.
Use cases¶
You're an analyst for an e-commerce company and you need to calculate and display the conversion rate for different marketing campaigns. You have a table with the number of clicks and the number of resulting purchases for each campaign.
WITH campaign_data AS (
SELECT
'Campaign A' AS campaign_name,
1000 AS clicks,
50 AS purchases
UNION ALL
SELECT
'Campaign B' AS campaign_name,
500 AS clicks,
20 AS purchases
UNION ALL
SELECT
'Campaign C' AS campaign_name,
2000 AS clicks,
150 AS purchases
)
SELECT
campaign_name,
bigfunctions.us.format_percentage(purchases, clicks, 2) AS conversion_rate
FROM campaign_data;
This query uses the format_percentage
function to calculate the conversion rate (purchases / clicks) for each campaign and format it as a percentage with two decimal places. The result would be a table like this:
+---------------+----------------+
| campaign_name | conversion_rate |
+---------------+----------------+
| Campaign A | 5.00 % |
| Campaign B | 4.00 % |
| Campaign C | 7.50 % |
+---------------+----------------+
This makes it easy to compare the effectiveness of different campaigns in a human-readable format. You could also use this function to calculate and display other percentages, such as sales growth rates, discount percentages, or return rates.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!