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! Learn more

Reply

Need DAX correction

Hi All,

 

I need dax help /correction here.. Can anyone pls help here..

 

test dax = 
IF(AND(
FILTER('SR','SR'[Complex]="LOST"),
FILTER('SR',CONTAINSSTRING('SR'[Holder],"TPA"))),
CALCULATE(COUNT('SR'[ID])),
IF(FILTER('SR',Not(CONTAINSSTRING('SR'[Holder],"TPA"))),
CALCULATE(COUNT('SR'[ID]))))
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PowerBIBeginer ,

First, let's look at nesting of IF functions. You have two IF functions in your expression, but there is no logical connection between them. This can result in calculations that are not as expected. You need to explicitly specify the relationship between the IF functions, for example, by using the ELSE keyword.

Second, you use the AND function in the first IF function, but you do not specify the relationship between the first and second conditions. You need to separate the two conditions with a comma, or use another logical operator (such as &&) to connect them.

Depending on your needs, you can try the following corrections:

Corrected DAX = 
VAR IsLost = 'SR'[Complex] = "LOST"
VAR ContainsTPA = CONTAINSSTRING('SR'[Holder], "TPA")

RETURN
IF(
    IsLost && ContainsTPA,
    CALCULATE(COUNT('SR'[ID])),
    IF(
        NOT ContainsTPA,
        CALCULATE(COUNT('SR'[ID]))
    )
)

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @PowerBIBeginer ,

First, let's look at nesting of IF functions. You have two IF functions in your expression, but there is no logical connection between them. This can result in calculations that are not as expected. You need to explicitly specify the relationship between the IF functions, for example, by using the ELSE keyword.

Second, you use the AND function in the first IF function, but you do not specify the relationship between the first and second conditions. You need to separate the two conditions with a comma, or use another logical operator (such as &&) to connect them.

Depending on your needs, you can try the following corrections:

Corrected DAX = 
VAR IsLost = 'SR'[Complex] = "LOST"
VAR ContainsTPA = CONTAINSSTRING('SR'[Holder], "TPA")

RETURN
IF(
    IsLost && ContainsTPA,
    CALCULATE(COUNT('SR'[ID])),
    IF(
        NOT ContainsTPA,
        CALCULATE(COUNT('SR'[ID]))
    )
)

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the reply v-yilong-msft 🙂 This works..

can anyone please suggest here.. this is something scalar value error

PijushRoy
Super User
Super User

Hi @PowerBIBeginer 

Please check 

 

test_dax =
IF (
    AND (
        FILTER ( 'SR', 'SR'[Complex] = "LOST" ),
        FILTER ( 'SR', CONTAINSSTRING ( 'SR'[Holder], "TPA" ) )
    ),
    CALCULATE ( COUNT ( 'SR'[ID] ) ),
    IF (
        FILTER ( 'SR', NOT CONTAINSSTRING ( 'SR'[Holder], "TPA" ) ),
        CALCULATE ( COUNT ( 'SR'[ID] ) )
    )
)

 

 


Let me know if that works for you


If your requirement is solved, please mark THIS ANSWER as SOLUTION ✔️ and help other users find the solution quickly. Please hit the LIKE 👍 button if this comment helps you.

Thanks
Pijush
Linkedin




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





Hi, Thanks for your reply. But you only made change in design otherwise it is same what I wrote..

 

The one which I posted, giving me error

- The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

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