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
Ghazaleh
Frequent Visitor

SQL to DAX

How do I convert this from SQL to DAX format?

CASE
    WHEN dp.payment_status IN ('Approved', 'PaidInFull') THEN 0
    ELSE fp.revenue_amount_{{currency}}
END AS booking_amount,
CASE
    WHEN dp.payment_status IN ('Approved', 'PaidInFull') THEN fp.revenue_amount_{{currency}}
    ELSE 0
END AS payment_amount,
1 ACCEPTED SOLUTION

Hi @Ghazaleh 

 

The RELATED function requires that a relationship exists between the current table and the table with related information. If a relationship does not exist between "fp" and "dp", you must create a relationship. You can create a relationship on their common column e.g. Order ID, Payment ID...

 

Then if you want to add two columns in "fp", you can try the following DAX. You might need to correct the table and column names. 

booking_amount =
IF (
    RELATED ( 'dp'[payment_status] ) IN { "Approved", "PaidInFull" },
    0,
    'fp'[revenue_amount_]
)
payment_amount =
IF (
    RELATED ( 'dp'[payment_status] ) IN { "Approved", "PaidInFull" },
    'fp'[revenue_amount_],
    0
)

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

3 REPLIES 3
AllisonKennedy
Super User
Super User

@Ghazaleh What's the FROM clause of your SQL statement and how are the fp and dp tables related in Power BI?

 

A CASE statement is basically a SWITCH function in DAX or a Conditional Column in Power Query. 

 

Use

Booking_amount = 

SWITCH (  TRUE(), 

dp.payment_status IN {'Approved', 'PaidInFull'} , 0, 

fp.revenue_amount_{{currency}}

)

 

 

But you'll need to clean up the syntax and table names.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

the payment status comes from a different table (dp) and revenue amount comes from (fp). the approved and paidinfull are values in payment status columns. How can I use "related" function in this case statement to pull these variables from both tables?

Hi @Ghazaleh 

 

The RELATED function requires that a relationship exists between the current table and the table with related information. If a relationship does not exist between "fp" and "dp", you must create a relationship. You can create a relationship on their common column e.g. Order ID, Payment ID...

 

Then if you want to add two columns in "fp", you can try the following DAX. You might need to correct the table and column names. 

booking_amount =
IF (
    RELATED ( 'dp'[payment_status] ) IN { "Approved", "PaidInFull" },
    0,
    'fp'[revenue_amount_]
)
payment_amount =
IF (
    RELATED ( 'dp'[payment_status] ) IN { "Approved", "PaidInFull" },
    'fp'[revenue_amount_],
    0
)

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

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.