简体   繁体   中英

Converting a Case Transform in ADF Mapping DataFlow

I am currently building a DF in ADF where i am converting the below Query which is already placed in another ETL tool called BigDecission. The Query looks like below

SELECT
    Asset_ID,
    MAX(CASE WHEN meter = 'LTPC' THEN reading_date ELSE NULL END) AS LTPC_Date,
    MAX(CASE WHEN meter = 'LTPC' THEN page_Count ELSE NULL END) AS LTPC,
  
FROM
    mv_latest_asset_read
GROUP BY
    Asset_ID

While converting this piece in ADF DF i have used AGGREGATE transform and done GROUP BY "ASSET_ID". In the AGGREGATES Tab i am deriving the column "LTPC_DATE" and "LTPC" with below mentioned code.

LTPC_DATE ---- > max(case(METER=='LTPC',READING_DATE)) 在此处输入图像描述

LTPC ---- > max(case(METER=='LTPC',PAGE_COUNT)) 在此处输入图像描述

But in the output i am getting null values which shouldn't be the case. Can anyone identify the right way to do it.

I followed the same approach to reproduced above and getting proper result.

Please check the below:

My source data:

在此处输入图像描述

Here I have taken 2 additional columns using derived column transformation and giving a sample value.

在此处输入图像描述

Group By and aggregate:

在此处输入图像描述

Used max(case(condtion,expression)) here.

在此处输入图像描述

Result in Data preview:

在此处输入图像描述

Try to check your projection in the source. Also, transform this to a sink file and check if it gives correct result or not.

If it still gives same, you can try maxIf(condition, expression) as suggested by @Mark Kromer MSFT .

在此处输入图像描述

The above also giving the same result for me.

If your source is a database, you can try query option in the source of dataflow and give the above query.

在此处输入图像描述

After Importing projection, you can see the desired result in the Data preview.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM