|
| 1 | +# Inventory Snapshots Data Cleaning Documentation |
| 2 | + |
| 3 | +Comprehensive data profiling, cleaning, standardization, and transformation pipeline for the `bronze.inventory_snapshots` dataset. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +# Objective |
| 8 | + |
| 9 | +The primary goal of this pipeline is to transform raw and inconsistent inventory snapshot data into a clean, analytics-ready dataset. |
| 10 | + |
| 11 | +The transformation process includes: |
| 12 | + |
| 13 | +- Data profiling |
| 14 | +- Pattern analysis |
| 15 | +- Type validation |
| 16 | +- Data standardization |
| 17 | +- Null handling |
| 18 | +- Derived metric calculation |
| 19 | +- Business rule enforcement |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +# Source Table |
| 24 | + |
| 25 | +```sql |
| 26 | +bronze.inventory_snapshots |
| 27 | +``` |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +# Column-Level Cleaning Strategy |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +# 1. snapshot_date |
| 36 | + |
| 37 | +## Problems Identified |
| 38 | + |
| 39 | +- Multiple date formats |
| 40 | +- Mixed separators (`/` and `-`) |
| 41 | +- Month name formats |
| 42 | +- Ambiguous DD/MM/YYYY and MM/DD/YYYY patterns |
| 43 | + |
| 44 | +## Supported Formats |
| 45 | + |
| 46 | +| Format | Example | |
| 47 | +|---|---| |
| 48 | +| YYYY-MM-DD | 2025-01-10 | |
| 49 | +| YYYY/MM/DD | 2025/01/10 | |
| 50 | +| MM/DD/YYYY | 01/10/2025 | |
| 51 | +| DD/MM/YYYY | 10/01/2025 | |
| 52 | +| MM-DD-YYYY | 01-10-2025 | |
| 53 | +| DD-MM-YYYY | 10-01-2025 | |
| 54 | +| Mon DD, YYYY | Jan 10, 2025 | |
| 55 | +| Month DD, YYYY | January 10, 2025 | |
| 56 | + |
| 57 | +## Cleaning Logic |
| 58 | + |
| 59 | +- Used `TRY_CONVERT` |
| 60 | +- Applied conditional format detection using `LIKE` |
| 61 | +- Resolved ambiguous date formats using validation rules |
| 62 | + |
| 63 | +--- |
| 64 | + |
| 65 | +# 2. product_id |
| 66 | + |
| 67 | +## Problems Identified |
| 68 | + |
| 69 | +- Null values |
| 70 | +- Empty strings |
| 71 | +- Non-numeric values |
| 72 | + |
| 73 | +## Cleaning Logic |
| 74 | + |
| 75 | +```sql |
| 76 | +TRY_CONVERT(INT, product_id) |
| 77 | +``` |
| 78 | + |
| 79 | +Invalid values are converted to `NULL`. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +# 3. product_name |
| 84 | + |
| 85 | +## Problems Identified |
| 86 | + |
| 87 | +- Null values |
| 88 | +- Empty strings |
| 89 | +- Leading/trailing spaces |
| 90 | + |
| 91 | +## Cleaning Logic |
| 92 | + |
| 93 | +- Applied `TRIM` |
| 94 | +- Replaced invalid values with `'Unknown'` |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +# 4. sku |
| 99 | + |
| 100 | +## Problems Identified |
| 101 | + |
| 102 | +- Null values |
| 103 | +- Empty strings |
| 104 | +- Whitespace inconsistencies |
| 105 | + |
| 106 | +## Cleaning Logic |
| 107 | + |
| 108 | +- Applied `TRIM` |
| 109 | +- Replaced invalid values with `'Unknown'` |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +# 5. category |
| 114 | + |
| 115 | +## Problems Identified |
| 116 | + |
| 117 | +- Case inconsistency |
| 118 | +- Trailing spaces |
| 119 | +- Multiple category naming variations |
| 120 | + |
| 121 | +## Example Issues |
| 122 | + |
| 123 | +| Raw Value | Cleaned Value | |
| 124 | +|---|---| |
| 125 | +| electronics | Electronics | |
| 126 | +| ELECTRONICS | Electronics | |
| 127 | +| electronics | Electronics | |
| 128 | + |
| 129 | +## Cleaning Logic |
| 130 | + |
| 131 | +- Applied `TRIM` |
| 132 | +- Applied `LOWER` |
| 133 | +- Standardized using `CASE WHEN` |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +# 6. stock_on_hand |
| 138 | + |
| 139 | +## Problems Identified |
| 140 | + |
| 141 | +- Negative values |
| 142 | +- Invalid integers |
| 143 | +- Null values |
| 144 | + |
| 145 | +## Cleaning Logic |
| 146 | + |
| 147 | +```sql |
| 148 | +TRY_CONVERT(INT, stock_on_hand) |
| 149 | +``` |
| 150 | + |
| 151 | +Negative and invalid values are converted to `NULL`. |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +# 7. stock_reserved |
| 156 | + |
| 157 | +## Problems Identified |
| 158 | + |
| 159 | +- Negative values |
| 160 | +- Invalid numeric formats |
| 161 | + |
| 162 | +## Cleaning Logic |
| 163 | + |
| 164 | +- Validated numeric conversion |
| 165 | +- Converted invalid values to `NULL` |
| 166 | + |
| 167 | +--- |
| 168 | + |
| 169 | +# 8. stock_available |
| 170 | + |
| 171 | +## Problems Identified |
| 172 | + |
| 173 | +- Missing values |
| 174 | +- Invalid integers |
| 175 | + |
| 176 | +## Cleaning Logic |
| 177 | + |
| 178 | +If `stock_available` is missing: |
| 179 | + |
| 180 | +```sql |
| 181 | +stock_on_hand - stock_reserved |
| 182 | +``` |
| 183 | + |
| 184 | +Otherwise: |
| 185 | + |
| 186 | +```sql |
| 187 | +TRY_CONVERT(INT, stock_available) |
| 188 | +``` |
| 189 | + |
| 190 | +--- |
| 191 | + |
| 192 | +# 9. reorder_level |
| 193 | + |
| 194 | +## Problems Identified |
| 195 | + |
| 196 | +- Negative values |
| 197 | +- Invalid numeric formats |
| 198 | + |
| 199 | +## Cleaning Logic |
| 200 | + |
| 201 | +Invalid values are converted to `NULL`. |
| 202 | + |
| 203 | +--- |
| 204 | + |
| 205 | +# 10. unit_cost |
| 206 | + |
| 207 | +## Problems Identified |
| 208 | + |
| 209 | +- Currency symbols |
| 210 | +- Mixed numeric formats |
| 211 | + |
| 212 | +## Example Issues |
| 213 | + |
| 214 | +| Raw Value | Cleaned Value | |
| 215 | +|---|---| |
| 216 | +| $12.50 | 12.50 | |
| 217 | + |
| 218 | +## Cleaning Logic |
| 219 | + |
| 220 | +- Removed `$` |
| 221 | +- Converted using `TRY_CONVERT(DECIMAL(10,2))` |
| 222 | + |
| 223 | +--- |
| 224 | + |
| 225 | +# 11. unit_price |
| 226 | + |
| 227 | +## Problems Identified |
| 228 | + |
| 229 | +- Currency symbols |
| 230 | +- Comma-separated values |
| 231 | +- Mixed formatting |
| 232 | + |
| 233 | +## Example Issues |
| 234 | + |
| 235 | +| Raw Value | Cleaned Value | |
| 236 | +|---|---| |
| 237 | +| $1,200.50 | 1200.50 | |
| 238 | +| 1,22.00 | 122.00 | |
| 239 | + |
| 240 | +## Cleaning Logic |
| 241 | + |
| 242 | +- Removed `$` |
| 243 | +- Removed `,` |
| 244 | +- Applied `TRY_CONVERT(DECIMAL(10,2))` |
| 245 | + |
| 246 | +--- |
| 247 | + |
| 248 | +# 12. inventory_value |
| 249 | + |
| 250 | +## Business Logic |
| 251 | + |
| 252 | +Derived metric calculated using: |
| 253 | + |
| 254 | +```sql |
| 255 | +unit_price * stock_on_hand |
| 256 | +``` |
| 257 | + |
| 258 | +## Purpose |
| 259 | + |
| 260 | +Represents estimated inventory valuation based on available stock and selling price. |
| 261 | + |
| 262 | +--- |
| 263 | + |
| 264 | +# 13. warehouse_location |
| 265 | + |
| 266 | +## Problems Identified |
| 267 | + |
| 268 | +- Case inconsistencies |
| 269 | +- Null values |
| 270 | +- Mixed naming formats |
| 271 | + |
| 272 | +## Example Issues |
| 273 | + |
| 274 | +| Raw Value | Cleaned Value | |
| 275 | +|---|---| |
| 276 | +| wh-a1 | WH-A1 | |
| 277 | +| WH-a1 | WH-A1 | |
| 278 | + |
| 279 | +## Cleaning Logic |
| 280 | + |
| 281 | +- Applied `UPPER` |
| 282 | +- Standardized warehouse naming |
| 283 | +- Replaced missing values with `'Unknown'` |
| 284 | + |
| 285 | +--- |
| 286 | + |
| 287 | +# 14. store_id |
| 288 | + |
| 289 | +## Problems Identified |
| 290 | + |
| 291 | +- Null values |
| 292 | +- Empty strings |
| 293 | +- Invalid numeric values |
| 294 | + |
| 295 | +## Business Observation |
| 296 | + |
| 297 | +A significant number of records contain `NULL` store IDs, which may represent: |
| 298 | + |
| 299 | +- Warehouse-only inventory |
| 300 | +- Unassigned inventory |
| 301 | +- Centralized stock |
| 302 | +- Missing store mappings |
| 303 | + |
| 304 | +## Cleaning Logic |
| 305 | + |
| 306 | +```sql |
| 307 | +TRY_CONVERT(INT, store_id) |
| 308 | +``` |
| 309 | + |
| 310 | +--- |
| 311 | + |
| 312 | +# Final Clean Dataset |
| 313 | + |
| 314 | +The final transformation produces a fully standardized inventory dataset suitable for: |
| 315 | + |
| 316 | +- Reporting |
| 317 | +- Analytics |
| 318 | +- Dashboarding |
| 319 | +- Inventory monitoring |
| 320 | +- Business intelligence workflows |
| 321 | + |
| 322 | +--- |
| 323 | + |
| 324 | +# Key Data Engineering Concepts Applied |
| 325 | + |
| 326 | +- Data profiling |
| 327 | +- Pattern recognition |
| 328 | +- Standardization |
| 329 | +- Defensive casting |
| 330 | +- Business-rule validation |
| 331 | +- Derived metric calculation |
| 332 | +- Null handling |
| 333 | +- Data quality enforcement |
| 334 | + |
| 335 | +--- |
| 336 | + |
| 337 | +# Architectural Notes |
| 338 | + |
| 339 | +The pipeline follows a layered transformation approach: |
| 340 | + |
| 341 | +| Layer | Purpose | |
| 342 | +|---|---| |
| 343 | +| Bronze | Raw source data | |
| 344 | +| Silver | Cleaned and standardized data | |
| 345 | +| Gold | Business metrics and analytics | |
| 346 | + |
| 347 | +--- |
| 348 | + |
| 349 | +# Final Output Fields |
| 350 | + |
| 351 | +| Column | |
| 352 | +|---| |
| 353 | +| snapshot_date | |
| 354 | +| product_id | |
| 355 | +| product_name | |
| 356 | +| sku | |
| 357 | +| category | |
| 358 | +| stock_on_hand | |
| 359 | +| stock_reserved | |
| 360 | +| stock_available | |
| 361 | +| reorder_level | |
| 362 | +| unit_cost | |
| 363 | +| unit_price | |
| 364 | +| inventory_value | |
| 365 | +| warehouse_location | |
| 366 | +| store_id | |
| 367 | + |
| 368 | +--- |
| 369 | + |
| 370 | +# Outcome |
| 371 | + |
| 372 | +The resulting dataset is significantly more reliable, standardized, and analytics-ready compared to the original raw bronze-layer data. |
0 commit comments