Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Sql Query to DAX

Hi All,

 

Could somebody help me to write the below SQL statement in DAX.

 

No of repeat orders from existing customer 

 

select count(distinct ord_cd),Ord_Cust_Id from FCT_ORD_LINE ord  inner join DIM_STS STS on STS.Sts_Id= ORD.Ord_Sts_Id
AND STS.Sts_Text NOT IN ('Cancelled','Expired') where Ord_Crt_Dt between (Period) and Ord_Cust_Id in (sel Ord_Cust_Id from FCT_ORD_LINE ord inner join DIM_STS STS on STS.Sts_Id= ORD.Ord_Sts_Id AND STS.Sts_Text NOT IN ('Cancelled','Expired')
where Ord_Crt_Dt < Period ))"

 

Thanks & Regards,

Rajeev

 

 

1 ACCEPTED SOLUTION
v-huizhn-msft
Employee
Employee

Hi @Anonymous,

First, you can type the SQL statement when you import data from SQL Server, type the SQL statement in the following box(highlighted in red line).

1.PNG


In your model, you import FCT_ORD_LINE and DIM_STS tables seperately, please follow the steps below.

1. Create a relationship between FCT_ORD_LINE and DIM_STS tables trough STS.Sts_Id= ORD.Ord_Sts_Id. 

2. Create a measure using the formula below.

measure =
CALCULATE (
    DISTINCTCOUNT ( [ord_cd] ),
    FILTER (
        DIM_STS,
        [Sts_Text}<>'Cancelled'||[Sts_Text}<>'Expired'||[Ord_Crt_Dt] < Period
    )
)


3. Create a table visual, select [Ord_Cust_Id] and [measure] as values level, you will get expected result.

Best Regards,
Angelia

View solution in original post

1 REPLY 1
v-huizhn-msft
Employee
Employee

Hi @Anonymous,

First, you can type the SQL statement when you import data from SQL Server, type the SQL statement in the following box(highlighted in red line).

1.PNG


In your model, you import FCT_ORD_LINE and DIM_STS tables seperately, please follow the steps below.

1. Create a relationship between FCT_ORD_LINE and DIM_STS tables trough STS.Sts_Id= ORD.Ord_Sts_Id. 

2. Create a measure using the formula below.

measure =
CALCULATE (
    DISTINCTCOUNT ( [ord_cd] ),
    FILTER (
        DIM_STS,
        [Sts_Text}<>'Cancelled'||[Sts_Text}<>'Expired'||[Ord_Crt_Dt] < Period
    )
)


3. Create a table visual, select [Ord_Cust_Id] and [measure] as values level, you will get expected result.

Best Regards,
Angelia

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.