public inbox for [email protected]  
help / color / mirror / Atom feed
Destination Table - Condition Amount 0
2+ messages / 2 participants
[nested] [flat]

* Destination Table - Condition Amount 0
@ 2024-08-08 16:35 Anthony Apollis <[email protected]>
  2024-08-08 16:56 ` Re: Destination Table - Condition Amount 0 Adrian Klaver <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Anthony Apollis @ 2024-08-08 16:35 UTC (permalink / raw)
  To: [email protected]

I need your assistance with an ETL process that runs every six months.
Currently, we are in Calendar Year/FY 2025, which started in July 2024.

The issue is with the "Condition Amount" for FY 2025. Data comes through
correctly until the "Insert Data Into Task" step (please see the attached
screenshot). However, it appears that the code responsible for the "Update
PD Credit" step is not functioning as expected.
[image: image.png]


The destination table [Turkey - NCD Revenue Reporting Model_Table_Model] is
receiving data for FY 2025, but the "*Condition Amount*" column contains
zeros for 2025. Please see the attached sample data for reference.

To help diagnose the issue, I have included the following:

DDL for all three tables.

Insert/Update scripts for the two tasks as depicted in the screenshot above.

Sample raw data for the two tables.

SSIS can also be found attached for better understanding

Sample data for the "Insert Data Into

INSERT INTO "Prod"."Turkey - LEC invoices raised_table_SAP BW"
SELECT
    "Sold to Party",
    "Sold to Party Name",
    "Billing Document",
    "Material",
    "Material Name",
    "Profit Center w o controlling area",
    "Profit Center w/o controlling area Name",
    "Condition Type",
    "Condition Type Name",
    "Fiscal year period",
    REPLACE(REPLACE(REPLACE(REPLACE("Condition Amount",' 0TR',''),',',''),'(','-'),')','')::FLOAT AS "Condition Amount",
    REPLACE(REPLACE(REPLACE(REPLACE("Condition Quantity",' EA',''),',',''),'(','-'),')','')::FLOAT AS "Condition Quantity",
    "Loaddate",
    "Month"
FROM "Stag"."Turkey - LEC invoices raised_table_SAP BW" AS NCD
WHERE
    DATE("Loaddate") = (SELECT MAX(DATE("Loaddate")) FROM "Stag"."Turkey - LEC invoices raised_table_SAP BW");

-------------------------------------

INSERT INTO "Prod"."Turkey - NCD Revenue Reporting Model_Table_Model"
SELECT
    'PD Credit ABPA' AS "Flow Type",
    "PD Credit ABPA"."Sender Sold to Party",
    "PD Credit ABPA"."Sender Sold to Party Name",
    "PD Credit ABPA"."Fiscal Year",
    "PD Credit ABPA"."Period",
    CASE 
        WHEN NCD_EXCL."Order Quantity" IS NULL OR NCD_EXCL."Order Quantity" LIKE 'Excluded' THEN
            0
        WHEN NCD_EXCL."Order Quantity" LIKE 'NCD Valid' THEN
            "PD Credit ABPA"."Total Pd Credit"
        ELSE
            0
    END AS "Total Pd Credit",
    CASE 
        WHEN NCD_EXCL."Order Quantity" IS NULL THEN
            'Excluded'
        ELSE
            NCD_EXCL."Order Quantity"
    END AS "NCD Valid or Excluded",
    CURRENT_TIMESTAMP AS "Loaddate"
FROM
(
SELECT
    "PD Credit ABPA"."Sender Sold to Party",
    "PD Credit ABPA"."Sender Sold to Party Name",
    "PD Credit ABPA"."Fiscal Year",
    "PD Credit ABPA"."Period",
    (COALESCE(NULLIF("PD Credit ABPA"."Receiver Quantity",'')::FLOAT, 0) * COALESCE(NULLIF("PD Credit Value"."PD Credit",'')::FLOAT, 0)) AS "Total Pd Credit",
    "PD Credit ABPA"."Receiver Quantity",
    "PD Credit Value"."PD Credit"
FROM
(
SELECT
    "Sender Sold to Party",
    "Sender Sold to Party Name",
    'FY' || RIGHT("Posting Fisc Yr/Period",2) AS "Fiscal Year",
    'P' || RIGHT(LEFT("Posting Fisc Yr/Period",3),2) AS "Period",
    SUM(NULLIF("Receiver Quantity",'')::FLOAT) AS "Receiver Quantity"
FROM "Prod"."Turkey - PD Movements_Table_Other" AS "PD Credit ABPA"
WHERE
    RIGHT("Posting Fisc Yr/Period",2) > '21'
AND
    "Movement Material" NOT LIKE 'Movement Material'
GROUP BY
    "Sender Sold to Party",
    "Sender Sold to Party Name",
    'FY' || RIGHT("Posting Fisc Yr/Period",2),
    'P' || RIGHT(LEFT("Posting Fisc Yr/Period",3),2)
)  AS "PD Credit ABPA"
LEFT JOIN
(SELECT
    DISTINCT
    NULLIF("Sender Sold To's"::VARCHAR, '') AS "Sender Sold To's",
    NULLIF("PD Credit"::FLOAT, 0) AS "PD Credit",
    "Period - Start",
    "Period - End",
    "FY - Start",
    "FY - End"
FROM "Prod"."Turkey - PD Credit Amounts_View_Other" AS "PD Credit Value"
) AS "PD Credit Value"
ON
    "PD Credit ABPA"."Sender Sold to Party" = "PD Credit Value"."Sender Sold To's"
AND
(
    NULLIF(REPLACE("PD Credit ABPA"."Period",'P','')::FLOAT, 0) >= NULLIF(REPLACE("PD Credit Value"."Period - Start",'P','')::FLOAT, 0)
AND "PD Credit ABPA"."Fiscal Year" = "PD Credit Value"."FY - Start"
AND
    NULLIF(REPLACE("PD Credit ABPA"."Period",'P','')::FLOAT, 0) <= NULLIF(REPLACE("PD Credit Value"."Period - End",'P','')::FLOAT, 0)
AND "PD Credit ABPA"."Fiscal Year" = "PD Credit Value"."FY - End"
)
) AS "PD Credit ABPA"
LEFT JOIN
(
SELECT
    "Sold to Party",
    "Period",
    "FY",
    "Order Quantity"
FROM(
  SELECT 
    DISTINCT 
    NULLIF("Sold to Party"::VARCHAR, '') AS "Sold to Party",
    COALESCE("P01", 'Excluded') AS "P01",
    COALESCE("P02", 'Excluded') AS "P02",
    COALESCE("P03", 'Excluded') AS "P03",
    COALESCE("P04", 'Excluded') AS "P04",
    COALESCE("P05", 'Excluded') AS "P05",
    COALESCE("P06", 'Excluded') AS "P06",
    COALESCE("P07", 'Excluded') AS "P07",
    COALESCE("P08", 'Excluded') AS "P08",
    COALESCE("P09", 'Excluded') AS "P09",
    COALESCE("P10", 'Excluded') AS "P10",
    COALESCE("P11", 'Excluded') AS "P11",
    COALESCE("P12", 'Excluded') AS "P12",
    "FY"
FROM "Prod"."Turkey - NCD Exclusions List_Table_Other" AS NCD_EXCL
WHERE
    "Sold to Party" IS NOT NULL
) AS NCD_EXCL
UNPIVOT
(
    "Order Quantity" 
FOR
    "Period"
IN ("P01","P02","P03","P04","P05","P06","P07","P08","P09","P10","P11","P12")
) AS NCD_EXCL
) AS NCD_EXCL
ON
    "PD Credit ABPA"."Sender Sold to Party" = NCD_EXCL."Sold to Party"
AND
    "PD Credit ABPA"."Period" = NCD_EXCL."Period"
AND
    "PD Credit ABPA"."Fiscal Year" = NCD_EXCL."FY"
);

INSERT INTO "Prod"."Turkey - PD Movements_Table_Other"
SELECT
    "Movement Material",
    "Movement Material Name",
    "Sender",
    "Sender Name",
    "Sender Channel",
    "Sender Sold to Party",
    "Sender Sold to Party Name",
    '#' AS "Sender Reporting Grandparent",
    '#' AS "Sender Reporting Parent",
    "Receiver",
    "Receiver Name",
    "Receiver Channel",
    "Receiver Sold to Party",
    "Receiver Sold to Party Name",
    '#' AS "Receiver Reporting Grandparent",
    '#' AS "Receiver Reporting Parent",
    "Sender Posting Type",
    "Receiver Posting Type",
    "Posting Process Date",
    "Posting Fisc Yr Period" AS "Posting Fisc Yr/Period",
    "Date of Dispatch",
    "Date of Notification",
    "Mvt Receiver EU Channel",
    '#' AS "Mvt Receiver Pricing Class",
    "Mvt Receiver Pricing Reclass",
    "Reference 1",
    "Reference 2",
    "Reference 3",
    REPLACE(REPLACE(REPLACE(REPLACE("Sender Quantity",' 0TR',''),',',''),'(','-'),')','')::FLOAT AS "Sender Quantity",
    REPLACE(REPLACE(REPLACE(REPLACE("Receiver Quantity",' EA',''),',',''),'(','-'),')','')::FLOAT AS "Receiver Quantity",
    REPLACE(REPLACE(REPLACE(REPLACE("Movement Count (UMI)",' EA',''),',',''),'(','-'),')','')::FLOAT AS "Movement Count (UMI)",
    REPLACE(REPLACE(REPLACE(REPLACE("Declaration Delay Days CKF",' EA',''),',',''),'(','-'),')','')::FLOAT AS "Declaration Delay Days CKF",
    REPLACE(REPLACE(REPLACE(REPLACE("Input Delay Days CKF",' EA',''),',',''),'(','-'),')','')::FLOAT AS "Input Delay Days CKF",
    "Month",
    "Loaddate"
FROM "Stag"."Turkey - PD Movements_Table_SAP BW" AS PD_CREDIT
WHERE
    PD_CREDIT."Movement Material" NOT LIKE 'Movement Material'
AND
    PD_CREDIT."Receiver Channel" LIKE 'PARTICIPATIVE DISTRI';

-------------------------------------

INSERT INTO "Prod"."Turkey - NCD Revenue Reporting Model_Table_Model"
SELECT
    'NCD Amount' AS "Flow Type",
    NCD_AMOUNT."Sold to Party",
    NCD_AMOUNT."Sold to Party Name",
    NCD_AMOUNT."Fiscal year",
    NCD_AMOUNT."Period",
    CASE 
        WHEN NCD_EXCL."Order Quantity" IS NULL OR NCD_EXCL."Order Quantity" LIKE 'Excluded' THEN
            0
        WHEN NCD_EXCL."Order Quantity" LIKE 'NCD Valid' THEN
            NCD_AMOUNT."Condition Amount"
        ELSE
            0
    END AS "Condition Amount",
    CASE 
        WHEN NCD_EXCL."Order Quantity" IS NULL THEN
            'Excluded'
        ELSE
            NCD_EXCL."Order Quantity"
    END AS "NCD Valid or Excluded",
    CURRENT_TIMESTAMP AS "Loaddate"
FROM
(
SELECT
    "Sold to Party",
    "Sold to Party Name",
    'FY' || RIGHT("Fiscal year period",2) AS "Fiscal year",
    'P' || RIGHT(LEFT("Fiscal year period",3),2) AS "Period",
    "Condition Amount"
FROM "Prod"."Turkey - LEC invoices raised_table_SAP BW" AS NCD_AMOUNT
WHERE
    NCD_AMOUNT."Condition Type Name" LIKE '%Channel%'
) AS NCD_AMOUNT
LEFT JOIN
(
SELECT
    "Sold to Party",
    "Period",
    "FY",
    "Order Quantity"
FROM(
  SELECT 
    DISTINCT 
    NULLIF("Sold to Party"::VARCHAR, '') AS "Sold to Party",
    COALESCE("P01", 'Excluded') AS "P01",
    COALESCE("P02", 'Excluded') AS "P02",
    COALESCE("P03", 'Excluded') AS "P03",
    COALESCE("P04", 'Excluded') AS "P04",
    COALESCE("P05", 'Excluded') AS "P05",
    COALESCE("P06", 'Excluded') AS "P06",
    COALESCE("P07", 'Excluded') AS "P07",
    COALESCE("P08", 'Excluded') AS "P08",
    COALESCE("P09", 'Excluded') AS "P09",
    COALESCE("P10", 'Excluded') AS "P10",
    COALESCE("P11", 'Excluded') AS "P11",
    COALESCE("P12", 'Excluded') AS "P12",
    "FY"
FROM "Prod"."Turkey - NCD Exclusions List_Table_Other" AS NCD_EXCL
WHERE
    "Sold to Party" IS NOT NULL
) AS NCD_EXCL
UNPIVOT
(
    "Order Quantity" 
FOR
    "Period"
IN ("P01","P02","P03","P04","P05","P06","P07","P08","P09","P10","P11","P12")
) AS NCD_EXCL
) AS NCD_EXCL
ON
    NCD_AMOUNT."Sold to Party" = NCD_EXCL."Sold to Party"
AND
    NCD_AMOUNT."Period" = NCD_EXCL."Period"
AND
    NCD_AMOUNT."Fiscal year" = NCD_EXCL."FY"
WHERE
    RIGHT(NCD_AMOUNT."Fiscal year",2) > '21'
AND
    (CASE 
        WHEN NCD_EXCL."Order Quantity" IS NULL OR NCD_EXCL."Order Quantity" LIKE 'Excluded' THEN
            0
        WHEN NCD_EXCL."Order Quantity" LIKE 'NCD Valid' THEN
            NCD_AMOUNT."Condition Amount"
        ELSE
            0
    END) IS NOT NULL;


Attachments:

  [image/png] image.png (138.6K, 3-image.png)
  download | view image

  [text/plain] POSTGRES.txt (9.0K, 4-POSTGRES.txt)
  download | inline:
INSERT INTO "Prod"."Turkey - LEC invoices raised_table_SAP BW"
SELECT
    "Sold to Party",
    "Sold to Party Name",
    "Billing Document",
    "Material",
    "Material Name",
    "Profit Center w o controlling area",
    "Profit Center w/o controlling area Name",
    "Condition Type",
    "Condition Type Name",
    "Fiscal year period",
    REPLACE(REPLACE(REPLACE(REPLACE("Condition Amount",' 0TR',''),',',''),'(','-'),')','')::FLOAT AS "Condition Amount",
    REPLACE(REPLACE(REPLACE(REPLACE("Condition Quantity",' EA',''),',',''),'(','-'),')','')::FLOAT AS "Condition Quantity",
    "Loaddate",
    "Month"
FROM "Stag"."Turkey - LEC invoices raised_table_SAP BW" AS NCD
WHERE
    DATE("Loaddate") = (SELECT MAX(DATE("Loaddate")) FROM "Stag"."Turkey - LEC invoices raised_table_SAP BW");

-------------------------------------

INSERT INTO "Prod"."Turkey - NCD Revenue Reporting Model_Table_Model"
SELECT
    'PD Credit ABPA' AS "Flow Type",
    "PD Credit ABPA"."Sender Sold to Party",
    "PD Credit ABPA"."Sender Sold to Party Name",
    "PD Credit ABPA"."Fiscal Year",
    "PD Credit ABPA"."Period",
    CASE 
        WHEN NCD_EXCL."Order Quantity" IS NULL OR NCD_EXCL."Order Quantity" LIKE 'Excluded' THEN
            0
        WHEN NCD_EXCL."Order Quantity" LIKE 'NCD Valid' THEN
            "PD Credit ABPA"."Total Pd Credit"
        ELSE
            0
    END AS "Total Pd Credit",
    CASE 
        WHEN NCD_EXCL."Order Quantity" IS NULL THEN
            'Excluded'
        ELSE
            NCD_EXCL."Order Quantity"
    END AS "NCD Valid or Excluded",
    CURRENT_TIMESTAMP AS "Loaddate"
FROM
(
SELECT
    "PD Credit ABPA"."Sender Sold to Party",
    "PD Credit ABPA"."Sender Sold to Party Name",
    "PD Credit ABPA"."Fiscal Year",
    "PD Credit ABPA"."Period",
    (COALESCE(NULLIF("PD Credit ABPA"."Receiver Quantity",'')::FLOAT, 0) * COALESCE(NULLIF("PD Credit Value"."PD Credit",'')::FLOAT, 0)) AS "Total Pd Credit",
    "PD Credit ABPA"."Receiver Quantity",
    "PD Credit Value"."PD Credit"
FROM
(
SELECT
    "Sender Sold to Party",
    "Sender Sold to Party Name",
    'FY' || RIGHT("Posting Fisc Yr/Period",2) AS "Fiscal Year",
    'P' || RIGHT(LEFT("Posting Fisc Yr/Period",3),2) AS "Period",
    SUM(NULLIF("Receiver Quantity",'')::FLOAT) AS "Receiver Quantity"
FROM "Prod"."Turkey - PD Movements_Table_Other" AS "PD Credit ABPA"
WHERE
    RIGHT("Posting Fisc Yr/Period",2) > '21'
AND
    "Movement Material" NOT LIKE 'Movement Material'
GROUP BY
    "Sender Sold to Party",
    "Sender Sold to Party Name",
    'FY' || RIGHT("Posting Fisc Yr/Period",2),
    'P' || RIGHT(LEFT("Posting Fisc Yr/Period",3),2)
)  AS "PD Credit ABPA"
LEFT JOIN
(SELECT
    DISTINCT
    NULLIF("Sender Sold To's"::VARCHAR, '') AS "Sender Sold To's",
    NULLIF("PD Credit"::FLOAT, 0) AS "PD Credit",
    "Period - Start",
    "Period - End",
    "FY - Start",
    "FY - End"
FROM "Prod"."Turkey - PD Credit Amounts_View_Other" AS "PD Credit Value"
) AS "PD Credit Value"
ON
    "PD Credit ABPA"."Sender Sold to Party" = "PD Credit Value"."Sender Sold To's"
AND
(
    NULLIF(REPLACE("PD Credit ABPA"."Period",'P','')::FLOAT, 0) >= NULLIF(REPLACE("PD Credit Value"."Period - Start",'P','')::FLOAT, 0)
AND "PD Credit ABPA"."Fiscal Year" = "PD Credit Value"."FY - Start"
AND
    NULLIF(REPLACE("PD Credit ABPA"."Period",'P','')::FLOAT, 0) <= NULLIF(REPLACE("PD Credit Value"."Period - End",'P','')::FLOAT, 0)
AND "PD Credit ABPA"."Fiscal Year" = "PD Credit Value"."FY - End"
)
) AS "PD Credit ABPA"
LEFT JOIN
(
SELECT
    "Sold to Party",
    "Period",
    "FY",
    "Order Quantity"
FROM(
  SELECT 
    DISTINCT 
    NULLIF("Sold to Party"::VARCHAR, '') AS "Sold to Party",
    COALESCE("P01", 'Excluded') AS "P01",
    COALESCE("P02", 'Excluded') AS "P02",
    COALESCE("P03", 'Excluded') AS "P03",
    COALESCE("P04", 'Excluded') AS "P04",
    COALESCE("P05", 'Excluded') AS "P05",
    COALESCE("P06", 'Excluded') AS "P06",
    COALESCE("P07", 'Excluded') AS "P07",
    COALESCE("P08", 'Excluded') AS "P08",
    COALESCE("P09", 'Excluded') AS "P09",
    COALESCE("P10", 'Excluded') AS "P10",
    COALESCE("P11", 'Excluded') AS "P11",
    COALESCE("P12", 'Excluded') AS "P12",
    "FY"
FROM "Prod"."Turkey - NCD Exclusions List_Table_Other" AS NCD_EXCL
WHERE
    "Sold to Party" IS NOT NULL
) AS NCD_EXCL
UNPIVOT
(
    "Order Quantity" 
FOR
    "Period"
IN ("P01","P02","P03","P04","P05","P06","P07","P08","P09","P10","P11","P12")
) AS NCD_EXCL
) AS NCD_EXCL
ON
    "PD Credit ABPA"."Sender Sold to Party" = NCD_EXCL."Sold to Party"
AND
    "PD Credit ABPA"."Period" = NCD_EXCL."Period"
AND
    "PD Credit ABPA"."Fiscal Year" = NCD_EXCL."FY"
);

INSERT INTO "Prod"."Turkey - PD Movements_Table_Other"
SELECT
    "Movement Material",
    "Movement Material Name",
    "Sender",
    "Sender Name",
    "Sender Channel",
    "Sender Sold to Party",
    "Sender Sold to Party Name",
    '#' AS "Sender Reporting Grandparent",
    '#' AS "Sender Reporting Parent",
    "Receiver",
    "Receiver Name",
    "Receiver Channel",
    "Receiver Sold to Party",
    "Receiver Sold to Party Name",
    '#' AS "Receiver Reporting Grandparent",
    '#' AS "Receiver Reporting Parent",
    "Sender Posting Type",
    "Receiver Posting Type",
    "Posting Process Date",
    "Posting Fisc Yr Period" AS "Posting Fisc Yr/Period",
    "Date of Dispatch",
    "Date of Notification",
    "Mvt Receiver EU Channel",
    '#' AS "Mvt Receiver Pricing Class",
    "Mvt Receiver Pricing Reclass",
    "Reference 1",
    "Reference 2",
    "Reference 3",
    REPLACE(REPLACE(REPLACE(REPLACE("Sender Quantity",' 0TR',''),',',''),'(','-'),')','')::FLOAT AS "Sender Quantity",
    REPLACE(REPLACE(REPLACE(REPLACE("Receiver Quantity",' EA',''),',',''),'(','-'),')','')::FLOAT AS "Receiver Quantity",
    REPLACE(REPLACE(REPLACE(REPLACE("Movement Count (UMI)",' EA',''),',',''),'(','-'),')','')::FLOAT AS "Movement Count (UMI)",
    REPLACE(REPLACE(REPLACE(REPLACE("Declaration Delay Days CKF",' EA',''),',',''),'(','-'),')','')::FLOAT AS "Declaration Delay Days CKF",
    REPLACE(REPLACE(REPLACE(REPLACE("Input Delay Days CKF",' EA',''),',',''),'(','-'),')','')::FLOAT AS "Input Delay Days CKF",
    "Month",
    "Loaddate"
FROM "Stag"."Turkey - PD Movements_Table_SAP BW" AS PD_CREDIT
WHERE
    PD_CREDIT."Movement Material" NOT LIKE 'Movement Material'
AND
    PD_CREDIT."Receiver Channel" LIKE 'PARTICIPATIVE DISTRI';

-------------------------------------

INSERT INTO "Prod"."Turkey - NCD Revenue Reporting Model_Table_Model"
SELECT
    'NCD Amount' AS "Flow Type",
    NCD_AMOUNT."Sold to Party",
    NCD_AMOUNT."Sold to Party Name",
    NCD_AMOUNT."Fiscal year",
    NCD_AMOUNT."Period",
    CASE 
        WHEN NCD_EXCL."Order Quantity" IS NULL OR NCD_EXCL."Order Quantity" LIKE 'Excluded' THEN
            0
        WHEN NCD_EXCL."Order Quantity" LIKE 'NCD Valid' THEN
            NCD_AMOUNT."Condition Amount"
        ELSE
            0
    END AS "Condition Amount",
    CASE 
        WHEN NCD_EXCL."Order Quantity" IS NULL THEN
            'Excluded'
        ELSE
            NCD_EXCL."Order Quantity"
    END AS "NCD Valid or Excluded",
    CURRENT_TIMESTAMP AS "Loaddate"
FROM
(
SELECT
    "Sold to Party",
    "Sold to Party Name",
    'FY' || RIGHT("Fiscal year period",2) AS "Fiscal year",
    'P' || RIGHT(LEFT("Fiscal year period",3),2) AS "Period",
    "Condition Amount"
FROM "Prod"."Turkey - LEC invoices raised_table_SAP BW" AS NCD_AMOUNT
WHERE
    NCD_AMOUNT."Condition Type Name" LIKE '%Channel%'
) AS NCD_AMOUNT
LEFT JOIN
(
SELECT
    "Sold to Party",
    "Period",
    "FY",
    "Order Quantity"
FROM(
  SELECT 
    DISTINCT 
    NULLIF("Sold to Party"::VARCHAR, '') AS "Sold to Party",
    COALESCE("P01", 'Excluded') AS "P01",
    COALESCE("P02", 'Excluded') AS "P02",
    COALESCE("P03", 'Excluded') AS "P03",
    COALESCE("P04", 'Excluded') AS "P04",
    COALESCE("P05", 'Excluded') AS "P05",
    COALESCE("P06", 'Excluded') AS "P06",
    COALESCE("P07", 'Excluded') AS "P07",
    COALESCE("P08", 'Excluded') AS "P08",
    COALESCE("P09", 'Excluded') AS "P09",
    COALESCE("P10", 'Excluded') AS "P10",
    COALESCE("P11", 'Excluded') AS "P11",
    COALESCE("P12", 'Excluded') AS "P12",
    "FY"
FROM "Prod"."Turkey - NCD Exclusions List_Table_Other" AS NCD_EXCL
WHERE
    "Sold to Party" IS NOT NULL
) AS NCD_EXCL
UNPIVOT
(
    "Order Quantity" 
FOR
    "Period"
IN ("P01","P02","P03","P04","P05","P06","P07","P08","P09","P10","P11","P12")
) AS NCD_EXCL
) AS NCD_EXCL
ON
    NCD_AMOUNT."Sold to Party" = NCD_EXCL."Sold to Party"
AND
    NCD_AMOUNT."Period" = NCD_EXCL."Period"
AND
    NCD_AMOUNT."Fiscal year" = NCD_EXCL."FY"
WHERE
    RIGHT(NCD_AMOUNT."Fiscal year",2) > '21'
AND
    (CASE 
        WHEN NCD_EXCL."Order Quantity" IS NULL OR NCD_EXCL."Order Quantity" LIKE 'Excluded' THEN
            0
        WHEN NCD_EXCL."Order Quantity" LIKE 'NCD Valid' THEN
            NCD_AMOUNT."Condition Amount"
        ELSE
            0
    END) IS NOT NULL;

  [image/png] invoices raised.png (138.5K, 5-invoices%20raised.png)
  download | view image

  [application/vnd.openxmlformats-officedocument.spreadsheetml.sheet] LEC Invoices Raised NCD.xlsx (15.8K, 6-LEC%20Invoices%20Raised%20NCD.xlsx)
  download

  [application/vnd.openxmlformats-officedocument.spreadsheetml.sheet] Key PD Movements.xlsx (13.8K, 7-Key%20PD%20Movements.xlsx)
  download

  [application/vnd.openxmlformats-officedocument.spreadsheetml.sheet] Turkey - NCD Revenue Reporting Model_Table_Model.xlsx (11.2K, 8-Turkey%20-%20NCD%20Revenue%20Reporting%20Model_Table_Model.xlsx)
  download

  [application/vnd.openxmlformats-officedocument.spreadsheetml.sheet] Data of Both Tables Till Insert Data Into Task.xlsx (13.4K, 9-Data%20of%20Both%20Tables%20Till%20Insert%20Data%20Into%20Task.xlsx)
  download

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Destination Table - Condition Amount 0
  2024-08-08 16:35 Destination Table - Condition Amount 0 Anthony Apollis <[email protected]>
@ 2024-08-08 16:56 ` Adrian Klaver <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Adrian Klaver @ 2024-08-08 16:56 UTC (permalink / raw)
  To: Anthony Apollis <[email protected]>; [email protected]

On 8/8/24 09:35, Anthony Apollis wrote:
> I need your assistance with an ETL process that runs every six months. 
> Currently, we are in Calendar Year/FY 2025, which started in July 2024.
> 
> The issue is with the "Condition Amount" for FY 2025. Data comes through 
> correctly until the "Insert Data Into Task" step (please see the 
> attached screenshot). However, it appears that the code responsible for 
> the "Update PD Credit" step is not functioning as expected.
> 
> image.png
> 
> 
> The destination table [Turkey - NCD Revenue Reporting Model_Table_Model] 
> is receiving data for FY 2025, but the "*Condition Amount*" column 
> contains zeros for 2025. Please see the attached sample data for reference.
> 
> To help diagnose the issue, I have included the following:
> 
> DDL for all three tables.
> 
> Insert/Update scripts for the two tasks as depicted in the screenshot above.
> 
> Sample raw data for the two tables.
> 
> SSIS can also be found attached for better understanding
> 
> Sample data for the "Insert Data Into
> 

Honestly I have not looked through all the files and probably won't. I 
did find this though:

CASE
         WHEN NCD_EXCL."Order Quantity" IS NULL OR NCD_EXCL."Order 
Quantity" LIKE 'Excluded' THEN
             0
         WHEN NCD_EXCL."Order Quantity" LIKE 'NCD Valid' THEN
             NCD_AMOUNT."Condition Amount"
         ELSE
             0

which looks suspicious in that it can turn a "Condition Amount" into 0.

I would start by running the SELECT that this is part of and seeing what 
it does to the data and if that is what you want it to do.

-- 
Adrian Klaver
[email protected]







^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-08-08 16:56 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-08-08 16:35 Destination Table - Condition Amount 0 Anthony Apollis <[email protected]>
2024-08-08 16:56 ` Adrian Klaver <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox