format_percentage¶
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.
Usage¶
Call or Deploy format_percentage
?
Call format_percentage
directly
The easiest way to use bigfunctions
format_percentage
function is deployed in 39 public datasets for all of the 39 BigQuery regions.- It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)
Public BigFunctions Datasets
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Deploy format_percentage
in your project
Why deploy?
- You may prefer to deploy
format_percentage
in your own project 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).
- Get started by reading the framework page
Deployment
format_percentage
function can be deployed with:
pip install bigfunctions
bigfun get format_percentage
bigfun deploy format_percentage
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 % |
+----------------------+
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.
Need help or Found a bug?
Get help using format_percentage
The community can help! Engage the conversation on Slack
We also provide professional suppport.
Report a bug about 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.
We also provide professional suppport.