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
Anonymous
Not applicable

Nested IF

Can anyone help me with the logic to create the below output: 

IF "Code" = S, then in the  "Wanding CE210" Output also = "S" & in the next line should be a blank
IF "Code" = P, then in the  "Wanding CE210" Output also = "P" & in the next line should be a blank
Thanks in advance.

s&p.PNG
The codes which have been created so far has been pasted below.

Wanding CE210 = 
var a = MAX('CE210'[Index1])
var b = CALCULATE (MAX('CE210'[ITDSC]) ,FILTER ( ALLEXCEPT('CE210',CE210[WKCTR],CE210[DATE]), 'CE210'[Index1] = a  - 1 ) )
var c = CALCULATE (MAX ( 'CE210'[SIZE] ),FILTER ( ALLEXCEPT('CE210',CE210[WKCTR],CE210[DATE]), 'CE210'[Index1] = a  - 1  ) )
var d = CALCULATE (MAX ( 'CE210'[HEIGHT] ),FILTER ( ALLEXCEPT('CE210',CE210[WKCTR],CE210[DATE]), 'CE210'[Index1] = a  - 1  ) )
var e = 
IF(MAX('CE210'[WKCTR]) = BLANK(),BLANK(),
IF(
    MAX('CE210'[LABORCODE]) = "S",
    "S" ,
    IF(
    MAX('CE210'[LABORCODE]) = "P",
    "P",
    IF(
    MAX('CE210'[LABORCODE]) = "C",
    "C",
    IF (SEARCH("598",MAX('CE210'[RTOOL]),,0)=0 && MAX('CE210'[HEIGHT]) <>d, "D",
        IF (
        MAX('CE210'[ITDSC]) = b,
            IF (
            MAX('CE210'[SIZE]) = c,
            "M",
            "A"
        ),
        "B"
    ))))))
return
e
Index1 = RANKX(FILTER('CE210','CE210'[WKCTR] = EARLIER(CE210[WKCTR]) && 'CE210'[DATE] = EARLIER('CE210'[DATE])),'CE210'[Start_Time],,ASC,Dense)
1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous  - It looks like you're already retrieving certain information from the previous row and loading them into variables, such as:

var b = CALCULATE (MAX('CE210'[ITDSC]) ,FILTER ( ALLEXCEPT('CE210',CE210[WKCTR],CE210[DATE]), 'CE210'[Index1] = a  - 1 ) )

You can load the CODE and Wanding CE210 from the previous row into variables:

var previous_code = CALCULATE (MAX('CE210'[CODE]) ,FILTER ( ALLEXCEPT('CE210',CE210[WKCTR],CE210[DATE]), 'CE210'[Index1] = a  - 1 ) )
var previous_wanding_ce210 = CALCULATE (MAX('CE210'[Wanding CE210]) ,FILTER ( ALLEXCEPT('CE210',CE210[WKCTR],CE210[DATE]), 'CE210'[Index1] = a - 1 ) )

Then, you can use IF like this:

IF(
    OR(
        AND(previous_code = "P", previous_wanding_ce210 = "P"),
        AND(previous_code = "S", previous_wanding_ce210 = "S")
),
BLANK(),
<Other Logic....>
)

Hope this helps,

Nathan

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
Top Kudoed Authors