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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

SQL to DAX convertion

Hi, everybody!

Need help from experienced DAX users in converting SQL to DAX. 

SQL query provided below.

I'm just starting learning DAX, so far this looks incredibly confusing to me(

 

WITH CTE_ALL_OOS AS
(
SELECT

OOS.INN,
OOS.MONTH,
sum(OOS.ACB) as sum_ACB,
sum(OOS.oosales1) as sum_oosales1,
sum(OOS.oosales2) as sum_oosales2,
sum(OOS.oosales3) as sum_oosales3,
sum(OOS.oosales4) as sum_oosales4

FROM

VW_F_CRPT_OOSALES as OOS
GROUP BY OOS.INN,
OOS.MONTH

)

SELECT

OOS.INN,
OOS.MONTH,
case

when

OOS.sum_ACB > 0

or

OOS.sum_oosales1 > 0

or

OOS.sum_oosales2 > 0

or

sum_oosales3 > 0 then 0

when

sum_oosales4 > 0 then 1

else 0
end as oosales4

FROM

CTE_ALL_OOS as OOS

 

Thanks for your help!

1 ACCEPTED SOLUTION

Hi @Anonymous

 

Here is the output:

v-xulin-mstf_0-1618972221154.png

 

The pbix file is attached, please try it.

 

Best Regards,

Link

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-xulin-mstf
Community Support
Community Support

Hi @Anonymous,

 

Could you provide sample data or screenshot of tables?

So that i can sure about the names of tables and columns.

 

Best Regard,

Link

Anonymous
Not applicable

Hi, @v-xulin-mstf ,

Thank you a lot for your interest. I am very grateful for all advice and help.
Screenshot with sample raw data below.

 

Bukato_deloitte_0-1618941906841.png

 

Kind Regards,

Alina

Hi @Anonymous

 

Here is the output:

v-xulin-mstf_0-1618972221154.png

 

The pbix file is attached, please try it.

 

Best Regards,

Link

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi, @v-xulin-mstf !

Thank you for your help! It'll help me in me next tasks!

 

Kind Regards,

Alina

DouweMeer
Post Prodigy
Post Prodigy

What I prefer to use is the expression SELECTCOLUMNS.

SELECT
A.Field1
A.Field2
FROM
Table A
WHERE
A.Field1 = 'A'

Becomes 

SELECTCOLUMNS
   filter ( 'table'
      'table'[Field1] = "A"
      )
   , "Field1" , [Field1]
   , "Field2" , [Field2]
   )

 You can use a combination of Union, Generate and Naturalinnerjoin to create a different context.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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