Hey man, can u send me the email signature please
last night got a little bad, my neck got covered in hives and I breathing got tight so I went to urgentcare. They couldn't give me a solid ID as to what was going on but pumped me full of steroids so I'm feeling okay now
Glad you're feeling okay now. Get well soon!
Hey there~ Where are you getting the zip files for the MPA cases?
under integrationns> campaigns folder on google drive
Do you know if they sometimes have dashes?
I hope you're feeling well today! hopefully you will get better soon and will see on you on Monday as I wont be here tomorrow
GM, I believe I have everything but can you check if left something on my desk and drawer pls?
GM, idk why it wont let me access the Miro. So just requested an access.
Sorry for replying late, back to back meetings all day, just having a moment now
I can approve access once I get back to laptop. Just went to grab some food
Sure thing' Apologies for the delay on that
Hey there, are you hopping in on the DBT training?
Hey has Ryan joined or just his firefly?
If he doesn't join after 10min I might hop- I have some health stuff going on and have a drs appt so I need to leave right at 2
ohh I'm sorry to hear that. Take care and get well soon.
Hey did ryan have you change any of the talk time stuff?
We are hearing Ryan very loud in the background. Difficult to hear you/Chevy
Hey there, reguarding that lead yesterday, it looks like it never changed over to the new campaign? https://tortintakeprofessionals.lawruler.com/update-lead.aspx?lead=708264
I saw it on TIP Financials Dashboard V.13 on the Billable Leads Tap it shows like this
It looks like that contract got signed under Bard Powerport - BCL - Simmons Cooper - Shield Legal, and my understanding is once a lead signs a contract with a firm, they can't get moved.
I see.. not sure tho at what stage they moved from one contract to the other
Are we 100% sure we aren't reading it backwards? Like it started as Crump / Lanier and got moved to BCL Simmons?
That im not sure... that would probably Ryan question
But from what Ryan was saying yesterday it's from BCL-Simmons to Crump-Lanier
Do you mind if I add edward to this with history so he can see what were talking about?
Hey Man, please come here when you are ready so we can do our meeting in Nick's office
```-- ==================================================================================================================== -- BillableLeadsWithRatesandleadspediadata SCHEDULED -- This acts as the primary table that feeds into shield_legal financial data -- Query is composed as a CTE which creates multiple temp tables and joins them -- ====================================================================================================================
CREATE OR REPLACE TABLE
tort-intake-professionals.Financial_Log_Dataset.Billable_Leads_With_Rates_and_lp AS
-- ====================================================================================================================
-- Billable Status Reference Table
-- Used to identify which statuses count as billable (specific to servicetype = RET)
-- ====================================================================================================================
WITH billablestatuses AS (
SELECT statusname
FROM tort-intake-professionals.tip_prod_application.io_tip_lr_status_rates -- 1 day refresh rate
WHERE billable = TRUE
AND servicetype = 'RET'
),
-- ==================================================================================================================== -- Full Lead Status History -- Converts raw status changes into timestamped PST time for later filtering -- ==================================================================================================================== leadstatushistory AS ( SELECT leadid, tostatus, TIMESTAMP(DATETIME(date), "America/LosAngeles") AS statuschangetimestampPST,
-- NEW COLUMN: Latest status per lead
FIRST_VALUE(tostatus) OVER (
PARTITION BY leadid
ORDER BY date DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS current_status
FROM tort-intake-professionals.lr_data.lead_history_status -- 15 minute refresh
),
-- ====================================================================================================================
-- Contact Info Lookup
-- Pulls first and last name of contacts for lead display purposes
-- ====================================================================================================================
contact_info AS (
SELECT
id AS contactid,
firstname,
lastname
FROM tort-intake-professionals.lr_data.contact -- 15 minute refresh
),
-- ====================================================================================================================
-- Lead Source Info
-- Used to map lead.sourceid to a descriptive source type like referal or not.
-- ====================================================================================================================
leadsourceinfo AS (
SELECT
id AS leadsourceid,
name AS leadsourcetype
FROM tort-intake-professionals.lr_data.lead_source -- 15 minute refresh
),
-- ====================================================================================================================
-- Lead Case Metadata
-- Core lookup for lead info including contact linkage and source ID
-- ====================================================================================================================
leadcasetype AS (
SELECT
l.id AS leadid,
SAFECAST(l.casetypeid AS STRING) AS lrid,
TRIM(l.casedescription) AS lpleadid,
l.displayname AS lrleaddisplayname,
l.createdate,
l.contactid,
c.firstname AS contactfirstname,
c.lastname AS contactlastname,
l.sourceid
FROM tort-intake-professionals.lr_data.lead l -- 15 minute refresh
LEFT JOIN contact_info c ON l.contactid = c.contactid
),
-- ==================================================================================================================== -- Latest Status Snapshot Per Lead -- Captures the most recent status update to join against billable statuses -- ==================================================================================================================== lateststatus AS ( SELECT lsh.leadid, lsh.tostatus, ROWNUMBER() OVER ( PARTITION BY lsh.leadid ORDER BY lsh.statuschangetimestampPST DESC ) AS rn FROM leadstatus_history lsh ),
-- ==================================================================================================================== -- Filtered Leads that Have Billable Status as Most Recent -- Ensures we only work with billable leads going forward -- ==================================================================================================================== billableleadsfiltered AS ( SELECT ls.leadid, lc.lrid, lc.lpleadid, lc.lrleaddisplayname, lc.createdate, lc.contactfirstname, lc.contactlastname, lc.sourceid FROM lateststatus ls JOIN billablestatuses bs ON LOWER(ls.tostatus) = LOWER(bs.statusname) JOIN leadcasetype lc ON ls.leadid = lc.leadid WHERE ls.rn = 1 ),
-- ==================================================================================================================== -- Earliest Time Lead Became Billable (via Signed E-Sign) -- Used for rate matching and time tracking -- ==================================================================================================================== earliestesign AS ( SELECT leadid, MIN(statuschangetimestampPST) AS earliestesign FROM leadstatus_history WHERE LOWER(tostatus) LIKE '%signed e-sign%' GROUP BY leadid ),
-- ==================================================================================================================== -- Core Billable Leads Table -- Enriches filtered billable leads with earliestesign time and sourceid passthrough -- ==================================================================================================================== billableleads AS ( SELECT bsf.leadid, bsf.lrid, bsf.lpleadid, bsf.lrleaddisplayname, bsf.createdate, bsf.contactfirstname, bsf.contactlastname, bsf.sourceid, ee.earliestesign FROM billableleadsfiltered bsf JOIN earliest_esign ee ON bsf.leadid = ee.leadid ),
-- ====================================================================================================================
-- Five9 Talk Time by Lead
-- Summarizes total billable seconds + minute-based revenue calculation
-- ====================================================================================================================
calltimeperlead AS (
SELECT
SAFECAST(leadid AS INT64) AS leadid,
SUM(billtimeseconds) AS totalbillableseconds,
SUM(billtimeseconds) / 60.0 AS totalbillableminutes,
SUM((billtimeseconds / 60.0) ** iocalltimeminuterate) AS totalminuteratecharge
FROM tort-intake-professionals.Financial_Log_Dataset.Billable_Call_Time_Five9 -- 15 minute refresh
GROUP BY leadid
),
-- ====================================================================================================================
-- Effective Rate Matching Table
-- Maps revenue rates over time to earliestesign of lead
-- ====================================================================================================================
rateswitheffective AS (
SELECT
**,
COALESCE(
TIMESTAMP(iobillablerateeffectivedatetime),
validfrom
) AS effective_datetime
FROM tort-intake-professionals.tip_prod_application.io_lr_case_types_revenue_rates_history -- 15 minute refresh
),
-- ====================================================================================================================
-- Leadspedia Contracts
-- Aggregates all contract IDs per lead ID
-- ====================================================================================================================
leadspediacontracts AS (
SELECT
LeadID AS lpleadid,
STRINGAGG(CAST(ContractID AS STRING), ',') AS contract_ids
FROM shield-legal-bi.leadspedia.all_sold_leads -- 1 hour refresh
GROUP BY LeadID
),
-- ====================================================================================================================
-- Leadspedia Enrichment Table
-- Basic leadspedia info pulled in for tracking (email, s1, score)
-- ====================================================================================================================
leadspediaallleads AS (
SELECT
leadID,
s1,
emailaddress,
leadscore
FROM shield-legal-bi.leadspedia.all_leads -- 1 hour refresh```
```),
-- ====================================================================================================================
-- PCTID Metadata Reference Table
-- Adds tort type, campaign tags, client firm info
-- ====================================================================================================================
pctidinfo AS (
SELECT
lawrulercasetypename,
broadtorttype,
generaltorttype,
campaigntags,
primaryclientfirm,
partnerfirms,
lawrulercasetypeid,
marketingsource,
allfirmsarray
FROM tort-intake-professionals.pctid_v2.pctid_v2 -- Manually updated, instant after that.
)
-- ==================================================================================================================== -- FINAL SELECT: All Values Together -- Includes lead details, revenue rates, client/tort metadata, contract info, and talk time revenue -- ==================================================================================================================== SELECT bl.leadid AS lawrulerleadid, bl.lrid AS lawrulercasetypeid, bl.lpleadid AS leadspedialeadid, bl.lrleaddisplayname AS lawrulerleaddisplayname, bl.createdate AS lawrulerleadcreatedate, lsh.currentstatus AS lawrulerleadstatuscurrent, bl.contactfirstname, bl.contactlastname, bl.earliestesign, pr.lawrulercasetypename, pr.broadtorttype, pr.generaltorttype, pr.campaigntags, pr.primaryclientfirm, pr.partnerfirms, pr.marketingsource, pr.allfirmsarray, sl.leadID AS leadspediafullid, sl.s1 AS leadspedias1, sl.emailaddress AS leademail, sl.leadscore, lpc.contractids, r.iocasetypebillablerate, r.iocalltimeminuterate, r.iocalltimeflatfee, r.inboundpayrollcostper, r.outboundscreeningpayrollcostper, r.outboundintakepayrollcostper, r.processingpayrollcostper, r.asapayrollcostper, ctpl.totalbillableseconds, ctpl.totalbillableminutes, ctpl.totalminuteratecharge AS talktimerevenueinUSD, lsid.leadsourcetype
-- ==================================================================================================================== -- JOIN LOGIC -- ==================================================================================================================== FROM billableleads bl LEFT JOIN leadspediaallleads sl ON bl.lpleadid = sl.leadID LEFT JOIN leadspediacontracts lpc ON bl.lpleadid = lpc.lpleadid LEFT JOIN rateswitheffective r ON bl.lrid = CAST(r.lrcasetypesid AS STRING) AND COALESCE(TIMESTAMP(r.iobillablerateeffectivedatetime), r.validfrom) <= bl.earliestesign LEFT JOIN pctidinfo pr ON bl.lrid = CAST(pr.lawrulercasetypeid AS STRING) LEFT JOIN calltimeperlead ctpl ON bl.leadid = ctpl.leadid LEFT JOIN leadsourceinfo lsid ON bl.sourceid = lsid.leadsourceid LEFT JOIN ( SELECT DISTINCT leadid, currentstatus FROM leadstatus_history ) lsh ON bl.leadid = lsh.leadid
-- ==================================================================================================================== -- TEST LEAD FILTERING: Excludes test data from final output -- ==================================================================================================================== WHERE IFNULL(NOT REGEXPCONTAINS(LOWER(CAST(bl.leadid AS STRING)), r'test'), TRUE) AND IFNULL(NOT REGEXPCONTAINS(LOWER(bl.lpleadid), r'test'), TRUE) AND IFNULL(NOT REGEXPCONTAINS(LOWER(bl.lrleaddisplayname), r'test'), TRUE) AND IFNULL(NOT REGEXPCONTAINS(LOWER(bl.contactfirstname), r'test'), TRUE) AND IFNULL(NOT REGEXPCONTAINS(LOWER(bl.contactlast_name), r'test'), TRUE)
-- ==================================================================================================================== -- ROW DEDUPLICATION: Keep latest effective rate per lead only -- ==================================================================================================================== QUALIFY ROWNUMBER() OVER ( PARTITION BY bl.leadid ORDER BY COALESCE(TIMESTAMP(r.iobillablerateeffectivedatetime), r.validfrom) DESC ) = 1
-- ==================================================================================================================== -- Default sort by date for easy filtering/viewing -- ==================================================================================================================== ORDER BY DATE(bl.earliest_esign) DESC;```
```-- ==================================================================================================================== -- BillableLeadsWithRatesandleadspediadata SCHEDULED -- This acts as the primary table that feeds into shield_legal financial data -- Query is composed as a CTE which creates multiple temp tables and joins them -- ====================================================================================================================
CREATE OR REPLACE TABLE
tort-intake-professionals.Financial_Log_Dataset.Billable_Leads_With_Rates_and_lp AS
-- ====================================================================================================================
-- Billable Status Reference Table
-- Used to identify which statuses count as billable (specific to servicetype = RET)
-- ====================================================================================================================
WITH billablestatuses AS (
SELECT statusname
FROM tort-intake-professionals.tip_prod_application.io_tip_lr_status_rates -- 1 day refresh rate
WHERE billable = TRUE
AND servicetype = 'RET'
),
-- ==================================================================================================================== -- Full Lead Status History -- Converts raw status changes into timestamped PST time for later filtering -- ==================================================================================================================== leadstatushistory AS ( SELECT leadid, tostatus, TIMESTAMP(DATETIME(date), "America/LosAngeles") AS statuschangetimestampPST,
-- NEW COLUMN: Latest status per lead
FIRST_VALUE(tostatus) OVER (
PARTITION BY leadid
ORDER BY date DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS current_status
FROM tort-intake-professionals.lr_data.lead_history_status -- 15 minute refresh
),
-- ====================================================================================================================
-- Contact Info Lookup
-- Pulls first and last name of contacts for lead display purposes
-- ====================================================================================================================
contact_info AS (
SELECT
id AS contactid,
firstname,
lastname
FROM tort-intake-professionals.lr_data.contact -- 15 minute refresh
),
-- ====================================================================================================================
-- Lead Source Info
-- Used to map lead.sourceid to a descriptive source type like referal or not.
-- ====================================================================================================================
leadsourceinfo AS (
SELECT
id AS leadsourceid,
name AS leadsourcetype
FROM tort-intake-professionals.lr_data.lead_source -- 15 minute refresh
),
-- ====================================================================================================================
-- Lead Case Metadata
-- Core lookup for lead info including contact linkage and source ID
-- ====================================================================================================================
leadcasetype AS (
SELECT
l.id AS leadid,
SAFECAST(l.casetypeid AS STRING) AS lrid,
TRIM(l.casedescription) AS lpleadid,
l.displayname AS lrleaddisplayname,
l.createdate,
l.contactid,
c.firstname AS contactfirstname,
c.lastname AS contactlastname,
l.sourceid
FROM tort-intake-professionals.lr_data.lead l -- 15 minute refresh
LEFT JOIN contact_info c ON l.contactid = c.contactid
),
-- ==================================================================================================================== -- Latest Status Snapshot Per Lead -- Captures the most recent status update to join against billable statuses -- ==================================================================================================================== lateststatus AS ( SELECT lsh.leadid, lsh.tostatus, ROWNUMBER() OVER ( PARTITION BY lsh.leadid ORDER BY lsh.statuschangetimestampPST DESC ) AS rn FROM leadstatus_history lsh ),
-- ==================================================================================================================== -- Filtered Leads that Have Billable Status as Most Recent -- Ensures we only work with billable leads going forward -- ==================================================================================================================== billableleadsfiltered AS ( SELECT ls.leadid, lc.lrid, lc.lpleadid, lc.lrleaddisplayname, lc.createdate, lc.contactfirstname, lc.contactlastname, lc.sourceid FROM lateststatus ls JOIN billablestatuses bs ON LOWER(ls.tostatus) = LOWER(bs.statusname) JOIN leadcasetype lc ON ls.leadid = lc.leadid WHERE ls.rn = 1 ),
-- ==================================================================================================================== -- Earliest Time Lead Became Billable (via Signed E-Sign) -- Used for rate matching and time tracking -- ==================================================================================================================== earliestesign AS ( SELECT leadid, MIN(statuschangetimestampPST) AS earliestesign FROM leadstatus_history WHERE LOWER(tostatus) LIKE '%signed e-sign%' GROUP BY leadid ),
-- ==================================================================================================================== -- Core Billable Leads Table -- Enriches filtered billable leads with earliestesign time and sourceid passthrough -- ==================================================================================================================== billableleads AS ( SELECT bsf.leadid, bsf.lrid, bsf.lpleadid, bsf.lrleaddisplayname, bsf.createdate, bsf.contactfirstname, bsf.contactlastname, bsf.sourceid, ee.earliestesign FROM billableleadsfiltered bsf JOIN earliest_esign ee ON bsf.leadid = ee.leadid ),
-- ====================================================================================================================
-- Five9 Talk Time by Lead
-- Summarizes total billable seconds + minute-based revenue calculation
-- ====================================================================================================================
calltimeperlead AS (
SELECT
SAFECAST(leadid AS INT64) AS leadid,
SUM(billtimeseconds) AS totalbillableseconds,
SUM(billtimeseconds) / 60.0 AS totalbillableminutes,
SUM((billtimeseconds / 60.0) ** iocalltimeminuterate) AS totalminuteratecharge
FROM tort-intake-professionals.Financial_Log_Dataset.Billable_Call_Time_Five9 -- 15 minute refresh
GROUP BY leadid
),
-- ====================================================================================================================
-- Effective Rate Matching Table
-- Maps revenue rates over time to earliestesign of lead
-- ====================================================================================================================
rateswitheffective AS (
SELECT
**,
COALESCE(
TIMESTAMP(iobillablerateeffectivedatetime),
validfrom
) AS effective_datetime
FROM tort-intake-professionals.tip_prod_application.io_lr_case_types_revenue_rates_history -- 15 minute refresh
),
-- ====================================================================================================================
-- Leadspedia Contracts
-- Aggregates all contract IDs per lead ID
-- ====================================================================================================================
leadspediacontracts AS (
SELECT
LeadID AS lpleadid,
STRINGAGG(CAST(ContractID AS STRING), ',') AS contract_ids
FROM shield-legal-bi.leadspedia.all_sold_leads -- 1 hour refresh
GROUP BY LeadID
),
-- ====================================================================================================================
-- Leadspedia Enrichment Table
-- Basic leadspedia info pulled in for tracking (email, s1, score)
-- ====================================================================================================================
leadspediaallleads AS (
SELECT
leadID,
s1,
emailaddress,
leadscore
FROM shield-legal-bi.leadspedia.all_leads -- 1 hour refresh```
@James Turner when u get a chance can you take a look whatโs the latest signed date is for this lead please 778522
Yes, but want to know the latest.. as we thought the lead might have been in manual review
Looks like it was 07/07/2025 11:57:28 AM ๐
or 07/05/2025 04:49:57 PM depending what you're looking for
Hey James, I have a question for you, what time you will be available today?
I'm working on some Ryan stuff that he wanted done ASAP- but I can answer some questions- Are you thinking like a hour long meeting or just some simple Qs?
I can make time now and get back to this- I'll head on over