Skip to content

1118 build combined sales qc view - #1120

Merged
Damonamajor merged 11 commits into
masterfrom
1118-build-combined-sales-qc-view
Nov 5, 2026
Merged

Damonamajor merged 11 commits into
masterfrom
1118-build-combined-sales-qc-view

Conversation

@Damonamajor

@Damonamajor Damonamajor commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

View with all sales in sale.mydec from 2020 onward that do not have a matching sale in iasworld.sales, joined on document number.

@Damonamajor Damonamajor linked an issue Nov 2, 2026 that may be closed by this pull request
@Damonamajor
Damonamajor requested a review from a team as a code owner November 2, 2026 21:02
Comment thread dbt/models/qc/docs.md Resolved
-- matching sale in iasWorld.
WITH mydec AS (
SELECT
mydec.*,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume that some PINs are getting rejected since they don't align with a valid address. I tried to match them with our vw_pin_address, but I don't know if we have a better way.

@jeancochrane jeancochrane left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good start to me! Let's get @wrridgeway to weigh in as the MyDec expert before we merge and share with stakeholders. I haven't requested his review yet since tests aren't yet passing; go ahead and do that once tests are passing and this is good to share.

Comment on lines +17 to +21
-- Normalize addresses so that MyDec unit numbers (e.g. "# 6S")
-- match the iasWorld format (e.g. "6S")
TRIM(REGEXP_REPLACE(
REPLACE(UPPER(mydec.line_1_street), '#', ''), '\s+', ' '
)) AS address_normalized,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion, non-blocking] I don't really think we need to bother with address matching at this point, since our stakeholders haven't identified it as a priority. Personally I would skip it at this stage, but I also don't mind leaving it in if you think it's important.

@Damonamajor Damonamajor Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave it in personally. I think some sales were based on firm headquarters rather than the addresses, but I'm not sure.

EDIT: And the best way to look through to validate the sales is also to query MLS sites, and address is needed for that. But, not all of them were returning to the listed PIN. It may be better as a T/F indicator rather than matching.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as we caveat that it is just for QC work.

@Damonamajor

Copy link
Copy Markdown
Contributor Author

@wrridgeway @jeancochrane
Checks are passing.

@wrridgeway wrridgeway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just reviewed construction correctness, not whether this output meets the intended use. Great work, just some minor suggestions primarily for readability and maintainability.

Comment on lines +49 to +53
mydec AS (
SELECT *
FROM mydec_all
WHERE doc_row_num = 1
),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably clearest just to let this (WHERE doc_row_num = 1) be a conditional in your main query, I don't think there needs to be an entire CTE for it.

Comment on lines +38 to +46
WHERE NOT EXISTS (
SELECT 1
FROM {{ source('iasworld', 'sales') }} AS sales
WHERE sales.deactivat IS NULL
AND sales.cur = 'Y'
-- Strip non-digit characters from iasWorld
AND REGEXP_REPLACE(sales.instruno, '[^0-9]', '')
= mydec_clean.document_number_clean
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code isn't wrong, but it feels a lot less clear than just doing a typical sql left anti join. This CTE could also use some commenting to explain what it's doing.

Suggested change
WHERE NOT EXISTS (
SELECT 1
FROM {{ source('iasworld', 'sales') }} AS sales
WHERE sales.deactivat IS NULL
AND sales.cur = 'Y'
-- Strip non-digit characters from iasWorld
AND REGEXP_REPLACE(sales.instruno, '[^0-9]', '')
= mydec_clean.document_number_clean
)
LEFT JOIN iasworld.sales AS sales
ON sales.deactivat IS NULL
AND sales.cur = 'Y'
AND REGEXP_REPLACE(sales.instruno, '[^0-9]', '') = mydec_clean.document_number_clean
WHERE sales.instruno is nul

WHERE doc_row_num = 1
),

pin_address AS (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure every CTE has a comment explaining its existence.

INNER JOIN pin_address
ON mydec.address_normalized = pin_address.address_normalized
AND mydec.city = pin_address.city
AND mydec.zip = pin_address.zip

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you tested this, or if it makes any difference, but i'd be interested to see what ignoring zip does. Hopefully nothing, but it would be a small bummer to say addresses that are the same but for a zip don't match.

@Damonamajor

Copy link
Copy Markdown
Contributor Author

@wrridgeway I simplified it a lot. Do you mind one more look at it?

@Damonamajor

Copy link
Copy Markdown
Contributor Author

I removed the address join. It didn't seem to work great and added in multi-pin sales as a flag.

@wrridgeway wrridgeway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! I'd bring back the window function you had before just to be sure this view always produces a unique set of document numbers and then you're good to go if this meets the stakeholders' desires.

@@ -0,0 +1,44 @@
-- View that returns all MyDec sales from 2020 onward that do not have a
-- matching sale in iasWorld. Output is unique by document_number.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output is unique by document_number, but I'm not sure we're doing anything here to actually enforce that assertion. You might want to bring back your window function just to be sure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I took it out because it wasn't necessary, but I'll just add it back in.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tested and saw that it isn't currently necessary, but I believe mydec.sale could be non-unique by doc no under certain conditions in the future.

@jeancochrane jeancochrane left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work you two!

@Damonamajor
Damonamajor merged commit 144cf1b into master Nov 5, 2026
11 checks passed
@Damonamajor
Damonamajor deleted the 1118-build-combined-sales-qc-view branch November 5, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build combined sales qc view

3 participants