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
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
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.