Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
3 years ago

Conversión de SQL a Dax

Por favor, ayúdame a convertir esta consulta SQL de un sistema heredado a dax. Usaré la segmentación de datos de fecha BETWEEN en Power BI con report_date. El report_date es dinámico en el sistema heredado. La consulta SQL obtiene los compradores habituales que realizaron una compra en los últimos 180 días. Estoy confundido cómo convertirlo a dax. Esta consulta es una consulta diferente de la última publicación.

Ejemplo de archivo de energía con datos:

https://drive.google.com/file/d/1SHFMwz53srJg3pwjQI4a7grBMyOGS-Ph/view?usp=sharing

Datos SQL:

ESCOGER
NVL(SUMA(mem_count),0) COMO repeat_shoppers,
CASO CUANDO SUMA(revenue_d) > 0 Y SUMA(mem_count) > 0 ENTONCES SUMA(revenue_d)/SUMA(mem_count) MÁS 0 FIN avg_spend_repeat_d
DE
(ESCOGER
CONTAR( DISTINTO mbr.membership_number) COMO mem_count ,
SUMA(demand_revenue) COMO revenue_d
DE dw_summary.ddh_product_detail_new pd,
( ( ESCOGER membership_number DE(
ESCOGER membership_number, CONTAR(DISTINTO order_number) COMO order_count
DE dw_summary.ddh_product_detail_new
DÓNDE report_date ENTRE '2023-02-02' Y '2020-09-19' --dinámico
Y digital_channel = 'OPIC'
Y membership_number NO ES NULL
AGRUPAR POR membership_number
TENIENTE CONTAR(DISTINTO order_number) > 1)
MENOS
SELECCIONAR DISTINTO membership_number
DE dw_summary.ddh_product_detail_new
DÓNDE report_date < '2020-02-02' Y report_date >= '2020-02-02'-180 --dinámico
Y digital_channel = 'OPIC'
Y membership_number NO ES NULL
)
UNIÓN
( SELECCIONAR DISTINTO membership_number
DE dw_summary.ddh_product_detail_new
DÓNDE report_date ENTRE '2020-02-02' Y '2020-09-19' --dinámico
Y digital_channel = 'OPIC'
Y membership_number NO ES NULL
CRUZAR
SELECCIONAR DISTINTO membership_number
DE dw_summary.ddh_product_detail_new
DÓNDE report_date < '2020-02-02' Y report_date >= '2020-02-02'-180 --dinámico
Y digital_channel = 'OPIC'
Y membership_number NO ES NULL
)
) MBR
DÓNDE pd.membership_number = mbr.membership_number
Y pd.digital_channel = 'OPIC'
Y report_date ENTRE '2020-02-02' Y '2020-09-19' --dinámico
);

1 Reply