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
Alex_Wynen
New Member

Help to understand a complex DAX query

Hi,

I am learning Power DAX, and I saw my previous workmate wrote a DAX query, but it is too complex to understand for me, could anyone help me understand it? like which part of the query runs first e.g. the last 'if' statement or the first 'if' statement. 

Many thanks

The query is below:

 

MyFlag =

IF(

     CALCULATE(COUNTROWS(Player), Player[PlayerScopeFlagDesc] = "Out Of Scope") = CALCULATE(COUNTROWS(Player)), "Out of Scope",

          IF(

               CALCULATE(COUNTROWS(Player), Player[PlayerScopeFlagDesc] = "Out Of Scope") > 0 && BillGroup[BillGroupName] = "MasterPlayerNo", "Out of Scope",

               IF(

                    CALCULATE(COUNTROWS(Player), Player[PlayerScopeFlagDesc] = "TBD") > 0, "TBD",

                     IF(

                         CALCULATE(COUNTROWS(Player), Player[PlayerScopeFlagDesc] = "In Scope") > 0, "In Scope", "Migrated"

                        )

                  )

         )

)

1 REPLY 1
ChiragGarg2512
Solution Sage
Solution Sage

In this expression, the first 'if' will get executed first and then the others in the same order.

 

It would be better to use the SWITCH statement instead of IF statement.

Here is the expression for switch statement:

MyFlag =
SWITCH (
TRUE (),
CALCULATE ( COUNTROWS ( Player ), Player[PlayerScopeFlagDesc] = "Out Of Scope" ) = CALCULATE ( COUNTROWS ( Player ) ), "Out of Scope",
CALCULATE ( COUNTROWS ( Player ), Player[PlayerScopeFlagDesc] = "Out Of Scope" ) > 0 && BillGroup[BillGroupName] = "MasterPlayerNo", "Out of Scope",
CALCULATE ( COUNTROWS ( Player ), Player[PlayerScopeFlagDesc] = "TBD" ) > 0, "TBD",
CALCULATE ( COUNTROWS ( Player ), Player[PlayerScopeFlagDesc] = "In Scope" ) > 0, "In Scope",
"Migrated"
)

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.