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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
llm
Frequent Visitor

SQL Case Statement to Dax

Hi In the instructions it says not to ask about SQL conversions but I'm willing to take a chance that someone can help . I am a beginner with Power Bi & Dax and having difficulty converting the following SQL case statement to Dax. All the appropriate relationships have been created. How do I recreate the nested statements and figure out how to enter 0 if the conditions are not met? Do I use a switch or calculate with variables?

Statement overview: Create a new column called "CurrRetain" . Populate it with APTD.Amount (if conditions are met) or 0 (if they are not).

WHEN APTD.PayType = (

                                      CASE

                                              WHEN APTD.PayCategory IS NULL

                                                      THEN APCO.RetPayType

                                              ELSE APPC.RetPayType

                                              END

                                      )

                               AND (

                                      APTD.PaidDate IS NULL

                                      OR APTD.PaidDate > GETDATE()

                                      )

                               AND APTH.InvDate <= GETDATE()

                               THEN (APTD.Amount)

                       ELSE 0

                       END AS 'CurrRetain'

 

Any help or suggestion in converting this to dax would be greatly appreciated.

 

1 ACCEPTED SOLUTION
bcdobbs
Community Champion
Community Champion

I would look at using SWITCH but in the form

 

SWITCH (

   True,

   Case1, Outcome1,

    Case2, Outcome2

   ....

)

 

See the example in https://dax.guide/switch/



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

3 REPLIES 3
v-luwang-msft
Community Support
Community Support

Hi @llm ,

Has your problem been solved, if so, please consider Accept a correct reply as the solution or share your own solution to help others find it.If not solved ,could you pls share your sample data in SQL,and expected output.

Remember to remove confidential data.

 

 

Best Regards
Lucien

bcdobbs
Community Champion
Community Champion

I would look at using SWITCH but in the form

 

SWITCH (

   True,

   Case1, Outcome1,

    Case2, Outcome2

   ....

)

 

See the example in https://dax.guide/switch/



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
llm
Frequent Visitor

This worked

CurrRetain = SWITCH(TRUE,

IF (ISBLANK(APTD[PayCategory]),RELATED(APCO[RetPayType]),RELATED(APPC[RetPayType])) &&

(ISBLANK(APTD[PaidDate])) || ((APTD[PaidDate]) > TODAY()) &&

(RELATED(APTH[InvDate]) <= TODAY()),

APTD[Amount],

0

)

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors