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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
KHP
Regular Visitor

Nested IF statements and filtering on a column

I have a measure that calculates the vendor rank based on revenue.  I am attempting to return a 1 if the rank is >=10 if it includes "NTTD" or return 1 for the rank <10 and 1 for "NTTD."  In the or statement i am trying to ensure that NTTD is marked as 1.  This throws an error "a single column for "vendor" in "apptbl_vendor" cannot be determined.  I have asked chatgpt and it is no help with this.  any input is greatly appreciated.
 
IsTopVendor =
IF(
    CALCULATE([Vendor Rank],app_tblVendors[Vendor]="NTTD")<=10,
    IF(
        CALCULATE([Vendor Rank])<=10,
        1,
        0
    ),
    If(
        CALCULATE([Vendor Rank],app_tblVendors[Vendor]="NTTD")>10,
        If(
            OR(
                app_tblVendors[Vendor]="NTTD",
                CALCULATE([Vendor Rank])<10
            )
        1,
        0
        )
    )
)
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

The error is in this line:

 

app_tblVendors[Vendor]="NTTD",

 

 

You are comparing a column to a string without specifying a specific row in that column.

 

Try this instead since you wanted to check if it includes "NTTD":

 

"NTTD" IN VALUES ( app_tblVendors[Vendor] )

 

 

As a side note, I much prefer using SWITCH to nested IF statements and using variables helps too.

 

Try this refactoring:

 

IsTopVendor =
VAR _Rank = [Vendor Rank]
VAR _RankNTTD = CALCULATE ( [Vendor Rank], app_tblVendors[Vendor] = "NTTD" )
VAR _IncludesNTTD = "NTTD" IN VALUES ( app_tblVendors[Vendor] )
RETURN
    SWITCH (
        TRUE (),
        _RankNTTD <= 10 && _Rank <= 10, 1,
        _RankNTTD >  10 && ( _Rank < 10 || _IncludesNTTD ), 1,
        0
    )

 

 

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

The error is in this line:

 

app_tblVendors[Vendor]="NTTD",

 

 

You are comparing a column to a string without specifying a specific row in that column.

 

Try this instead since you wanted to check if it includes "NTTD":

 

"NTTD" IN VALUES ( app_tblVendors[Vendor] )

 

 

As a side note, I much prefer using SWITCH to nested IF statements and using variables helps too.

 

Try this refactoring:

 

IsTopVendor =
VAR _Rank = [Vendor Rank]
VAR _RankNTTD = CALCULATE ( [Vendor Rank], app_tblVendors[Vendor] = "NTTD" )
VAR _IncludesNTTD = "NTTD" IN VALUES ( app_tblVendors[Vendor] )
RETURN
    SWITCH (
        TRUE (),
        _RankNTTD <= 10 && _Rank <= 10, 1,
        _RankNTTD >  10 && ( _Rank < 10 || _IncludesNTTD ), 1,
        0
    )

 

 

Helpful resources

Announcements
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.