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

Create a Column Based on Conditions

Hi everyone,

 

I am new to power bi and need help with regard to the following requirements. 

 

Reference NoMPLNRCRTRFCode
200AgricultureNewNew0
200AgricultureNewNew0
200AgricultureNewNew1
200AgricultureNewNew0
200AgricultureNewNew0
200AgricultureNewNew0
228AgricultureNewNew0
228AgricultureNewNew0
228AgricultureNewNew0
268AgricultureNewNew0
26AgricultureReturningRWC0
26AgricultureReturningRWC0
26AgricultureReturningRWC0
353AgricultureReturningROC0
353AgricultureReturningROC0
41BiologyNewNew0
41BiologyNewNew0
41BiologyNewNew0
41BiologyNewNew0

 

I want to create a new column BCLL.

 

- If MPL = Agriculture, NR = New, and Code = 1 in any of the rows with the same Reference No, return New Student.

From the above table, the first 6 rows have the same reference no and only 1 has a corresponding code of 1.

Because one of the codes is 1, MPL = Agriculture, and NR = New, the output for all the 6 rows should be New Student.

 

- If MPL = Agriculture, NR = New and Code = 0 for all the row with the same Reference No, return Addional.

From the above table, rows 7 to 10 have the same reference number, and code = 0 for all of them.

Because all the code is 0, MPL = Agriculture, and NR = New, the output for all the 4 rows should be Additional.

 

- If MPL is not equal to Agriculture and NR is not equal to New, return column CRTRF.

From the above table, NR is not equal to New in rows 11 to 15, they will return column CRTRF.

 

- If MPL is not equal to Agriculture and NR is not equal to New, return column CRTRF.

From the above table, MPL is not equal to Agriculture in rows 16 to 19, they will return column CRTRF.

 

The final output will look like the following table.

 

Please note that the actual table consists of more than 50,000 rows, this is just a sample.

 

Reference NoMPLNRCRTRFCodeBCLL
200AgricultureNewNew0New Student
200AgricultureNewNew0New Student
200AgricultureNewNew1New Student
200AgricultureNewNew0New Student
200AgricultureNewNew0New Student
200AgricultureNewNew0New Student
228AgricultureNewNew0Additional
228AgricultureNewNew0Additional
228AgricultureNewNew0Additional
268AgricultureNewNew0Additional
26AgricultureReturningRWC0RWC
26AgricultureReturningRWC0RWC
26AgricultureReturningRWC0RWC
353AgricultureReturningROC0ROC
353AgricultureReturningROC0ROC
41BiologyNewNew0New
41BiologyNewNew0New
41BiologyNewNew0New
41BiologyNewNew0

New

 

Please assist.

 

Thank you.

1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @Tee ,

Please try this:-

BCLL =
SWITCH (
    TRUE (),
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[MPL] = "Agriculture"
                && 'Table'[NR] = "New"
                && [Code] = 1
                && 'Table'[Reference No] = EARLIER ( 'Table'[Reference No] )
        )
    ) > 0, "New Student",
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[MPL] = "Agriculture"
                && 'Table'[NR] = "New"
                && [Code] = 0
                && 'Table'[Reference No] = EARLIER ( 'Table'[Reference No] )
        )
    ) > 0, "Addional",
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[MPL] <> "Agriculture"
                && 'Table'[NR] <> "New"
                && [Code] = 0
                && 'Table'[Reference No] = EARLIER ( 'Table'[Reference No] )
        )
    ) >= 0, 'Table'[CRTRF]
)

Output:-

Samarth_18_0-1649768223566.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

3 REPLIES 3
Samarth_18
Community Champion
Community Champion

Hi @Tee ,

Please try this:-

BCLL =
SWITCH (
    TRUE (),
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[MPL] = "Agriculture"
                && 'Table'[NR] = "New"
                && [Code] = 1
                && 'Table'[Reference No] = EARLIER ( 'Table'[Reference No] )
        )
    ) > 0, "New Student",
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[MPL] = "Agriculture"
                && 'Table'[NR] = "New"
                && [Code] = 0
                && 'Table'[Reference No] = EARLIER ( 'Table'[Reference No] )
        )
    ) > 0, "Addional",
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[MPL] <> "Agriculture"
                && 'Table'[NR] <> "New"
                && [Code] = 0
                && 'Table'[Reference No] = EARLIER ( 'Table'[Reference No] )
        )
    ) >= 0, 'Table'[CRTRF]
)

Output:-

Samarth_18_0-1649768223566.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Tee
New Member

Thank you for your response.

 

I encountered the following error:

 

DAX comparison operations do not support comparing values of type Integer with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.

 

I also want to note that I don't have [Reference] table as in the sample of the code below;

 

No]) ), [Reference]) , "New Student" ,

 

Do you mean Reference No column?

 

Thank you.

amitchandak
Super User
Super User

@Tee , Try a new column

New Column =
Switch( True() .
[Code] = Maxx(filter(Table, Table[MPL] = "Agriculture" && Table[NR] = "New" && [Code]= 1 && [Reference No] =earlier([Reference No]) ), [Reference]) , "New Student" ,
[Code] = Maxx(filter(Table, Table[MPL] = "Agriculture" && Table[NR] = "New" && [Code]= 0 && [Reference No] =earlier([Reference No]) ), [Reference]) ,"Addional",
[Code] = Maxx(filter(Table, Table[MPL] <> "Agriculture" && Table[NR] <> "New" && [Code]= 0 && [Reference No] =earlier([Reference No])), [Reference]) ,"CRTRF")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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