How do I get the sum of multiple action types from one column? - google-data-studio

Consider a pipeline campaign for marketing where we track 3 metrics:
New Leads
Booked Leads
Confirmed Leads
I want to create a filter to find the SUM of (2 and 3) Booked and Confirmed Leads.
Filter 1: For Booked leads - They should first have the Type NEW and BOOKED
Filter 2: For Confirmed leads - They should first have the Type NEW, BOOKED and CONFIRMED
I have some data in Google Sheets with Email, Type, and Date like the one attached:
Email
Type
Date
a#example.com
NEW
1-1-2022
b#example.com
NEW
1-2-2022
fff#example.com
NEW
1-3-2022
a#example.com
BOOKED
1-2-2022
b#example.com
BOOKED
1-3-2022
sway#example.com
BOOKED
1-3-2022
a#example.com
CONFIRMED
1-4-2022
gm#example.com
CONFIRMED
1-5-2022
I tried with this formula in Google Data Studio but it didn't work (It gives me 0):
SUM(CASE WHEN TYPE ='NEW' AND TYPE = 'BOOKED' THEN 1 ELSE 0 END)
OUTPUT Needed IN Google Data Studio:
I needed to have metrics for the following:
NEW LEADS - For getting this is quite easy since I filtered with TYPE = 'NEW'. Here we will have 3 (No filter is required)
BOOKED LEADS - For this, I need to check if the email has a type of NEW and also BOOKED, then I will count that as 1. (an example is a#example.com and b#example.com -
Both have NEW and BOOKED (where sum will be 2))
But for sway#example.com it doesn't have NEW leads Type, so it won't be counted.
CONFIRMED LEADS - For this, I need to check if the email has a type of NEW, BOOKED, and CONFIRMED, then I will count that as 1 (an example is a#example.com-
It has NEW, BOOKED, and CONFIRMED (that is a total of 1 email that the 3 action types - it will be considered as 'CONFIRMED LEADS' in Data Studio)
gm#example.com will not be considered because it doesn't have 'NEW' and "BOOKED" types.
Output Table
EMAIL
TYPE
a#example.com
NEW,BOOKED,CONFIRMED
b#example.com
NEW,BOOKED
fff#example.com
NEW
sway#example.com
BOOKED
gm#example.com
BOOKED
New Leads
Booked Leads
Confirmed Leads
3
2
1
The expected output is Scorecard of the following:
New Leads: 3 (Sum of leads that have the type of "NEW")
Booked Leads: 2 (Sum of leads that have type of "NEW' and "BOOKED")
Confirmed Leads: 1 ( Sum of leads that have the type of "NEW', "BOOKED" and "CONFIRMED")
Link to the Google Data Studio Report

Related

Apex/Salesforce/flow: Be able to increase price and clone/update product automatically

I asked a similar question before but I am still struggling and was not able to do what I was required to do and am coming back to this community for help.
I am trying to increase the price of the products on a quote in salesforce CPQ/Billing based on a field and to do this automatically.
The Setup
In Salesforce CPQ, If you go to account -> Contract -> Sales Service: There is a field called Price Increase %(PROD_Price_Increase__c)
A contract can have multiple quotes
What I want to do
When a quote has reached the final step a contract is created. In the contract I have the option to click a button called Amend. Which allows me to take the products in the existing quotes and amend it.
I want to create a batch job that does the following:
The Contract has these fields: Start Date (PROD_Start_Date__c), Price increase Date (PROD_Increase_Date__c), End Date (PROD_End_Date__c).
-- If the Price Increase Date is 12 months after the start date, these are the contracts that will need to be updated
-- For example, If the start date is 15 Feb 2023, Price increase is 1 Jan 2024, end date is 15 Feb 2025. Since the increase date is not 12 months, these contract should be ignored.
Main Task
When products who have a price increase 12 months after the start date, the contract should be able to 'amend' and update the quantity of the products and clone the products.
In the contract, the action buttons on top have "Amend". once clicked, it shows all the subscriptions products, you click next then it comes into the edit quote page.
Once here it shows all the products that were part of the contract and its quote. The net price filed for the original products will be '0'. These products will need to be cloned and the quantity for these to be applied to the cloned products. Once the quantity has been copied over, the original products quantity should change to 0.
After these products have a quantity of 0, the clone products should have the price increase. The value I mentioned from earlier Price Increase % (ROD_Price_Increase__c) value should be added to the Discount filed in the quote but as a minus value since we are doing an increase of price.
Once this has been done, we can submit/order the quote. This creates a new quote. Once the new quote has been created, I want to be able to update a filed in the quote - a checkbox that says order. I want to be able to check the value on it.
This all should be done automatically like though Apex and Flows.
Sorry for this long text and request. I apologise and know some of the information not be out of box or confusing. Its one of these challenges I have been facing with trying to automate this.

Google Data Studio convert metric to dimension not working

I have imported my GA4 data into Google Data Studio and am trying to see how many giftcards have been sold by their value.
The item revenue metric in GA4 is equal to the giftcard value (i.e. revenue = $200 therefore $200 giftcard was sold).
I want to breakdown sales by giftcard value like so:
Giftcard (revenue)
Count
$200
4
$250
3
$300
6
To do this, I need to set a copy of item revenue as a dimension rather than a metric.
In Google Data Studio, I can create a calculated field with the following formula that should convert the item revenue into text:
CAST(Item Revenue AS TEXT)
The problem I'm having is that while the formula sets the field type as text, it is still regarded by GDS as a metric and can't be used as a dimension.
Even when I try to add text, GDS still recognises the field as a number:
CONCAT(CAST(Item Revenue AS TEXT), " giftcard")
To use a metric as a dimension you can make a combination of data. When defining the graphic element (table, for example) and the respective data source, just create a data combination, but do not combine the data with any other source and just define the combination with the initial data itself. So you will have the same data structure only through a combined structure.
When making a combination of data, data studio recognizes all calculated fields (metrics) as dimensions. Thus, it is possible to make the conversion.

How do I find the annual number of new event guests in a list that spans over many years with repeat guests (Google Data Studio)?

I have a list of guests that come to my events. The list contains 10 years worth of events and guests. I want to know how many new guests are brand new each year, such that they've never attended my events before. How do I calculate this in the calculated field?
For example, John attended my event in 2011, 2012, and 2013. This means John was my new guest in 2011, but not 2012 or 2013. Therefore, the count of new guests in 2011 increments by one.
It is safe to assume that John uses the same email each time he registers for my event. Therefore, my resulting table should look like this:
Email
First Year of Attendance
johndoe#live.com
2011
0) Summary
Use EITHER #1 OR #2
#1: Use if two fields are required (Email and First_Year)
#2: Use if three fields are required (Email, Year and First_Year)
1) Aggregate Year by MIN
If the goal is only to show the 2 fields in the Table, then simply add the Year field as a Metric and aggregate by MIN:
2) Data Blending
To display all three fields in a single Table, one approach is using a Self Data Blend; the below does the trick where Email represents the field with Emails (such as johndoe#live.com) and Year the field with Year values, which can be a Number field (for example 2011) or a Date field (such as 01 Jan 2011):
2.1) Data Blending
Data Source 1
Join Key: Email
Dimension: Year
Data Source 2
Join Key: Email
Metric: First_Year; Rename: Year; Aggregation: MIN
2.2) Table
Data Source: Blended Data Source
Dimension 1: Email
Dimension 2: First_Year
Dimension 3: Year
Editable Google Data Studio Report (Embedded Google Sheets Data Source) and a GIF to elaborate:

How to create a dynamic - calculated - field in Salesforce?

Salesforce:
Every account has an agreement with my company. Once they have an agreement in place, they can start ordering products.
In the account record, I have a date field called "Agreement Approved On".
Ordered products are represented as "assets".
I want to create another field in the account record called "First Order Amount". This field should be populated dynamically, and should calculate the following:
Look for all of the account's assets created after the date field "Agreement Approved On".
Summarize the total of all assets ordered during the first order (within the same day).
Within the same day:
Let's assume the agreement was approved on January 1 2017. The
account started ordering on January 5 2017.
During January 5 2017, the account made 5 orders (8 different
assets), total is $1,000. This is the first order total - within the same
day.
After January 5 2017, the account made more orders, but they don't
count towards "first order amount".
So my question is - how do I create this "First Order Amount" field?
Thanks!
You need to setup a oncreate trigger on Asset taht will update the first order total amount field on Account.
In the trigger check whether now() > agreement approve date. If yes, check if there are any other assets with dateCreated < TODAY.
These two conditions will check whether there are any existing account assets and if the date is > agreement date. If there are existing assets, it means this is not the first order.
You can then get all asset amounts and add them and write the final amount to the account field.
See https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm
for trigger syntax
and https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm for date functions and literals.

Getting minimum values out of calculated table

I have:
a table with user names
a table indicating actions with columns for user name, action time, action name. Named events unique_events
I started collecting data on January. I want to have a column in my table of user names which indicates how long it has been since a user first used my application and the first of January.
So if a user first logged in in January, the value of the row with that user's name will be 0. If one logged in on March it will be 2.
I tried:
Column = DATEDIFF(01-01-2016, MIN(SELECTCOLUMNS(FILTER('events unique_events','events unique_events'[User Name] = Users[User Name]),"DatedTime", [DatedTime])),MONTH)
which returns an error saying the Min function needs a column reference.
I also tried the same with FirstDate instead of MIN which returned an error saying FirstDate can't be used with summarize functions.
Any other ideas on how to achieve this, or fix what I tried?
(for simplicity, I will call your table 'Events', and user login dates field 'User_Login_Date').
First, define your app start date as a measure:
App_Start_Date:= DATE(2016, 1, 1)
Then, define measure that finds min differences between Application Start Date and User Login dates:
User_Start_Diff=: MINX(Events, DATEDIFF([App_Start_Date], Events[User_Login_Date], Month))
Drop this measure into a pivot table against user names, and you should have your desired result.
How it works:
1) MINX goes record by record and calculates date differences for each customer login. It then finds minimum in the results;
2) When you drop the measure into a pivot table, it splits MINX results by customer, and recalculates min for each of them separately. You don't need to do the grouping.
Creation of [Start_Date] measure is not technically necessary but a matter of good style - don't hardcode values in your formulas, always create measures. You will thank yourself later when you need to make a change.

Resources