Hi There,
I have a table which is wrapped in multiple table transformers as I could not get them in one. Could be a limitation in my sql coding skills or maybe the macros work this way...but would would to get help on this. I want to reduce the number of table transformers I have as this page has reports as well which also includes more such macros.
The order from innermost (1) to outer transformer (4):
Table Transformer 1- This is ensuring the value entered casts in the right format such as a comma, after publishing. As in 100,000 instead of 100000
SELECT *, CAST(T1.'Contract Value In AUD' AS numwithcomma) As '*Contract Value In AUD' FROM T*
Table Transformer 2- This assigns a 'P' rating to the different range of values in column T1.Contract Value in AUD' and ends as a new column called 'Priority Rating'
SELECT *, CASE WHEN ('*Contract Value In AUD') <= 500000 THEN "P4"
WHEN ('*Contract Value In AUD') BETWEEN 500001 AND 5000000 THEN "P3"
WHEN ('*Contract Value In AUD') BETWEEN 5000001 AND 20000000 THEN "P2"
WHEN ('*Contract Value In AUD') >=20000000 THEN "P1"
END AS '*Priority Rating' FROM T*
Table Transformer 3- This gives a new column called 'Work Start Date' as per an interval condition given to each 'P' rating. The reference for calculation is column 'T1.Date Contract Will Expire'. Eg., if the value of a row in this column is '30 Sep 2024' and if it's a P4, then as per the interval condition given, the value published is '01 Aug 2024' (2 months as it satisfies the first condition)
Select *,
CASE WHEN '*Priority Rating' = "P4" THEN FORMATDATE(DATE_SUB(T1.'Date Contract will Expire',INTERVAL 2 MONTH))
WHEN '*Priority Rating' = "P3" THEN FORMATDATE(DATE_SUB(T1.'Date Contract will Expire',INTERVAL 3 MONTH))
WHEN '*Priority Rating' = "P2" THEN FORMATDATE(DATE_SUB(T1.'Date Contract will Expire',INTERVAL 5 MONTH))
WHEN '*Priority Rating' = "P1" THEN FORMATDATE(DATE_SUB(T1.'Date Contract will Expire',INTERVAL 6 MONTH))
END AS '*Work Start Date' FROM T*
Transformer 4- This one is just selecting the columns I want from the table and in the order I need