Oracle SQL to Dax

Please help me convert this SQL query from a legacy system into dax. I will be using the BETWEEN date slicer in Power BI. I am confused how to convert it to dax. The report_date is dynamic in the legacy system. The SQL Query gets the repeat shoppers who made a purchase in the last 180 days.

Sample Power File with Data:

Product_table.pbix (1.1 MB)

SQL Query:
SELECT
NVL(SUM(mem_count),0) AS repeat_shoppers,
CASE WHEN SUM(revenue_d) > 0 AND SUM(mem_count) > 0 THEN SUM(revenue_d)/SUM(mem_count) ELSE 0 END avg_spend_repeat_d
FROM
(SELECT
COUNT( DISTINCT mbr.membership_number) AS mem_count ,
SUM(demand_revenue) AS revenue_d
FROM dw_summary.ddh_product_detail_new pd,
( ( SELECT membership_number FROM(
SELECT membership_number, COUNT(DISTINCT order_number) AS order_count
FROM dw_summary.ddh_product_detail_new
WHERE report_date BETWEEN ‘2023-02-02’ AND ‘2020-09-19’ --dynamic
AND digital_channel = ‘OPIC’
AND membership_number IS NOT NULL
GROUP BY membership_number
HAVING COUNT(DISTINCT order_number) > 1)
MINUS
SELECT DISTINCT membership_number
FROM dw_summary.ddh_product_detail_new
WHERE report_date < ‘2020-02-02’ AND report_date >= ‘2020-02-02’-180 --dynamic
AND digital_channel = ‘OPIC’
AND membership_number IS NOT NULL
)
UNION
( SELECT DISTINCT membership_number
FROM dw_summary.ddh_product_detail_new
WHERE report_date BETWEEN ‘2020-02-02’ AND ‘2020-09-19’ --dynamic
AND digital_channel = ‘OPIC’
AND membership_number IS NOT NULL
INTERSECT
SELECT DISTINCT membership_number
FROM dw_summary.ddh_product_detail_new
WHERE report_date < ‘2020-02-02’ AND report_date >= ‘2020-02-02’-180 --dynamic
AND digital_channel = ‘OPIC’
AND membership_number IS NOT NULL
)
) mbr
WHERE pd.membership_number = mbr.membership_number
AND pd.digital_channel = ‘OPIC’
AND report_date BETWEEN ‘2020-02-02’ AND ‘2020-09-19’ --dynamic
);

Bumping this post for more visibility from our experts and users.

Hi @qrswin

Due to inactivity, we’d like to conclude that your inquiry was out of the experts’ and users’ bounds.

If you were sure you provided all pertinent context to your concerns and read how to use the forum more effectively and still find your question unanswered, your membership also comes with relevant resources that may help you with your Power BI education, so we advise that you check these resources as well.

While our users and experts do as much as reasonable to help you with your inquiries, not all concerns can be attended to especially if there are some learnings to be done. Thank you!