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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
qwaszx55
Frequent Visitor

Is there an easy way to convert SQL queries to DAX?

 

Trying to convert this to powerbi and I keep getting different numbers.

 

SQL:

,SUM(CASE WHEN (ISNULL(qi.warrantyflag,'') = 'Y' OR ISNULL(qi.osi_leasedflag,'') = 'Y') AND ISNULL(q.contype,'') <> 'CCO' THEN qi.qty*price

ELSE 0

END) Recurring

 

PowerBI (What I have so far):

Recurring =
Calculate(
sumx (QuoteItem,QuoteItem[QTY]*QuoteItem[PRICE]),
filter( Quote, isblank(Quote[CONTYPE]) || Quote[CONTYPE] <> "CCO"),
filter( QuoteItem, isblank(QuoteItem[WARRANTYFLAG]) || QuoteItem[WARRANTYFLAG] = "Y" ||isblank(QuoteItem[OSI_LEASEDFLAG]) || QuoteItem[OSI_LEASEDFLAG] ="Y")
)

 

This stuff makes my head hurt some times.

2 ACCEPTED SOLUTIONS

This has gotten me really close but what I'm having trouble figuring out is the CCO column is on a different table ('quote' instead of 'quoteitem') so I'm getting an error when trying to filter against being CCO. If that makes sense.

 

 Tried to use "related" but not sure if I'm doing that right.

 

Recurring2 = CALCULATE(
SUMX(
'QuoteItem',
'QuoteItem'[QTY]*'QuoteItem'[PRICE]) ,
FILTER('QuoteItem',
AND(
OR ('QuoteItem'[WARRANTYFLAG]="Y" ,'QuoteItem'[OSI_LEASEDFLAG]="Y")
,related(quote[contype])<>"CCO"
)
))

View solution in original post

Hi @qwaszx55,


 Tried to use "related" but not sure if I'm doing that right.

 

Recurring2 = CALCULATE(
SUMX(
'QuoteItem',
'QuoteItem'[QTY]*'QuoteItem'[PRICE]) ,
FILTER('QuoteItem',
AND(
OR ('QuoteItem'[WARRANTYFLAG]="Y" ,'QuoteItem'[OSI_LEASEDFLAG]="Y")
,related(quote[contype])<>"CCO"
)
))


Yes, the related function is correctly used here. 

 

Do you still have any question on this issue? if not, could you accept your reply above as solution to close this thread? Smiley Happy

 

Regards

View solution in original post

7 REPLIES 7
msbisyed
Regular Visitor


Hi Experts,

COULD you please help me out with SQL to DAX

SELECT sc.NET_PRICE,c.start_date,c.end_date
from [FACT].[SALES] SC INNER JOIN [DIM].[contract] c ON sc.sales_contract = c.ID,
(
select
d.DATEID ,
d.PER_NAME_YEAR,
d.PER_NAME_QTR,
d.CALENDAR_DATETIME,
d.CAL_MONTH,
d.CAL_QTR,
d.CAL_YEAR,
d.LAST_DAY_CAL_YEAR_FLG,
d.LAST_DAY_CAL_QTR_FLG ,
d.LAST_DAY_CAL_MNTH_FLG
from [oracle_edw_dev].[W_DAY_D] d
where 1=1
and d.LAST_DAY_CAL_QTR_FLG ='Y'
and d.CALENDAR_DATETIME <= GETDATE()
and d.CAL_QTR = '1' and d.CAL_YEAR = 2018
)qtr
where 1=1
and qtr.DATEID >= c.[start_date] and qtr.DATEID <=c.[end_date]
and c.[created_date] <= qtr.CALENDAR_DATETIME
and qtr.DATEID = c.[start_date]

Thanks in Advance

msbisyed
Regular Visitor


Hi Experts,

COULD you please help me out with SQL to DAX

SELECT sc.NET_PRICE,c.start_date,c.end_date
from [FACT].[SALES] SC INNER JOIN [DIM].[contract] c ON sc.sales_contract = c.ID,
(
select
d.DATEID ,
d.PER_NAME_YEAR,
d.PER_NAME_QTR,
d.CALENDAR_DATETIME,
d.CAL_MONTH,
d.CAL_QTR,
d.CAL_YEAR,
d.LAST_DAY_CAL_YEAR_FLG,
d.LAST_DAY_CAL_QTR_FLG ,
d.LAST_DAY_CAL_MNTH_FLG
from [oracle_edw_dev].[W_DAY_D] d
where 1=1
and d.LAST_DAY_CAL_QTR_FLG ='Y'
and d.CALENDAR_DATETIME <= GETDATE()
and d.CAL_QTR = '1' and d.CAL_YEAR = 2018
)qtr
where 1=1
and qtr.DATEID >= c.[start_date] and qtr.DATEID <=c.[end_date]
and c.[created_date] <= qtr.CALENDAR_DATETIME
and qtr.DATEID = c.[start_date]

Thanks in Advance

msbisyed
Regular Visitor

Could you Please help me out My SQL to DAX

SELECT sc.NET_PRICE,c.start_date,c.end_date
from [FACT].[SALES] SC INNER JOIN [DIM].[contract] c ON sc.sales_contract = c.ID,
(
select
d.DATEID ,
d.PER_NAME_YEAR,
d.PER_NAME_QTR,
d.CALENDAR_DATETIME,
d.CAL_MONTH,
d.CAL_QTR,
d.CAL_YEAR,
d.LAST_DAY_CAL_YEAR_FLG,
d.LAST_DAY_CAL_QTR_FLG ,
d.LAST_DAY_CAL_MNTH_FLG
from [oracle_edw_dev].[W_DAY_D] d
where 1=1
and d.LAST_DAY_CAL_QTR_FLG ='Y'
and d.CALENDAR_DATETIME <= GETDATE()
and d.CAL_QTR = '1' and d.CAL_YEAR = 2018
)qtr
where 1=1
and qtr.DATEID >= c.[start_date] and qtr.DATEID <=c.[end_date]
and c.[created_date] <= qtr.CALENDAR_DATETIME
and qtr.DATEID = c.[start_date]


Thanks in Advance

v-ljerr-msft
Employee
Employee

Hi @qwaszx55,

 

Have you tried the solution provided above? Does it work in your scenario? If it works, could you accept it as solution to close this thread?

 

If you still have any question on this issue, feel free to post here. Smiley Happy

 

Regards

This has gotten me really close but what I'm having trouble figuring out is the CCO column is on a different table ('quote' instead of 'quoteitem') so I'm getting an error when trying to filter against being CCO. If that makes sense.

 

 Tried to use "related" but not sure if I'm doing that right.

 

Recurring2 = CALCULATE(
SUMX(
'QuoteItem',
'QuoteItem'[QTY]*'QuoteItem'[PRICE]) ,
FILTER('QuoteItem',
AND(
OR ('QuoteItem'[WARRANTYFLAG]="Y" ,'QuoteItem'[OSI_LEASEDFLAG]="Y")
,related(quote[contype])<>"CCO"
)
))

Hi @qwaszx55,


 Tried to use "related" but not sure if I'm doing that right.

 

Recurring2 = CALCULATE(
SUMX(
'QuoteItem',
'QuoteItem'[QTY]*'QuoteItem'[PRICE]) ,
FILTER('QuoteItem',
AND(
OR ('QuoteItem'[WARRANTYFLAG]="Y" ,'QuoteItem'[OSI_LEASEDFLAG]="Y")
,related(quote[contype])<>"CCO"
)
))


Yes, the related function is correctly used here. 

 

Do you still have any question on this issue? if not, could you accept your reply above as solution to close this thread? Smiley Happy

 

Regards

Phil_Seamark
Employee
Employee

Hi @qwaszx55

 

I think this might be close...

 

Measure = CALCULATE(
                    SUMX(
                        'qi',
                        'qi'[qty]*'qi'[price]) ,
                    FILTER('qi', 
                        AND(
                            OR ('qi'[warrantyflag]="Y" ,'qi'[osi_leasedflag]="Y") 
                            ,'qi'[contype]<>"CCO")
                            )
                        )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.