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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Need help in converting SQL to DAX

Hi,

 

I am trying to convert the following SQL snippet into a DAX measure but got stuck as I am not sure how to handle DECODE.

 

SUM (
NVL (
ROUND (
NVL (Table.Retail_PNT, 0)
* DECODE (Item_Code, 'D', 0, 'I', 0, 1)
* CASE
WHEN Table.Amount* NVL ( (TO_DATE ( Table.Date_Time) - TO_DATE ( Table.Last_Movement_Date)), 28) < 1 THEN 0
ELSE ROUND ( NVL (Table.Amount, 0) * NVL ( (TO_DATE ( Table.Date_Time) - TO_DATE ( Table.Last_Movement_Date)), 0))
END
* DECODE (Table.Type_Code, 'SS', 0, 1)
,2)
,0))
AS Loss

 

Any help would be appreciated.

 

Thanks

Bob

1 REPLY 1
Anonymous
Not applicable

New column=

Var a=Round(if(Isblank(Table[Retail_PNT])=TRUE(),0,Table[Retail_PNT])* if(Table[Item_code] in {'"D","I"},0,1))

Var t=if(Datadiff(Table[Date_Time],table[Last_Movement_Date],Day)

<1,0,Round(if(Isblank(Table[Amount])=TRUE(),0,Table[Retail_PNT])*Datadiff(Table[Date_Time],table[Last_Movement_Date],Day))*if(table[Type code]="SS",0,1),2)

 

Return

If(a*t<>Blank(),a*t,0)

 

i am not sure i have closed parenthesis correctly or not.

 

Please check it from your side as well.

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

 

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.