cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Bukato_deloitte
Frequent Visitor

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 @Bukato_deloitte

 

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 @Bukato_deloitte,

 

Could you provide sample data or screenshot of tables?

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

 

Best Regard,

Link

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 @Bukato_deloitte

 

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

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
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors