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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
ritanoori
Resolver I
Resolver I

Need a help with if

Hi All 

Need your help pls. I have two columns col. 1 and col. 2 . I want to create new column using if and trying to reach 

 

if col.2 is "N/A" then check col. 1 , if col.1 starts with "SH" and col.1 is 14 characters then give col.1 else col. 2. 

 

but keep getting an error. ifif 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @ritanoori ;

According to the picture, maybe your symbol position is not very correct, so you can change dax to the following formula:

v-yalanwu-msft_0-1623378377292.png

SHIPMENT_NUMBER =
IF (
    'Fact_GL'[SH Number] = "N/A",
    IF (AND (
            LEFT ( 'Fact_GL'[Shipment Number], 2 ) = "SH",
            LEN ( 'Fact_GL'[Shipment Number] ) = 14),
        'Fact_GL'[Shipment Number],
        'Fact_GL'[SH Number]))

or 

SHIPMENT_NUMBER2 =
IF (
    'Fact_GL'[SH Number] = "N/A"
        && LEFT ( 'Fact_GL'[Shipment Number], 2 ) = "SH"
        && LEN ( 'Fact_GL'[Shipment Number] ) = 14,
    'Fact_GL'[Shipment Number],
    'Fact_GL'[SH Number])

The final output is shown below:

v-yalanwu-msft_1-1623378589675.png

Best Regards,
Community Support Team_ Yalan Wu
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
v-yalanwu-msft
Community Support
Community Support

Hi, @ritanoori ;

According to the picture, maybe your symbol position is not very correct, so you can change dax to the following formula:

v-yalanwu-msft_0-1623378377292.png

SHIPMENT_NUMBER =
IF (
    'Fact_GL'[SH Number] = "N/A",
    IF (AND (
            LEFT ( 'Fact_GL'[Shipment Number], 2 ) = "SH",
            LEN ( 'Fact_GL'[Shipment Number] ) = 14),
        'Fact_GL'[Shipment Number],
        'Fact_GL'[SH Number]))

or 

SHIPMENT_NUMBER2 =
IF (
    'Fact_GL'[SH Number] = "N/A"
        && LEFT ( 'Fact_GL'[Shipment Number], 2 ) = "SH"
        && LEN ( 'Fact_GL'[Shipment Number] ) = 14,
    'Fact_GL'[Shipment Number],
    'Fact_GL'[SH Number])

The final output is shown below:

v-yalanwu-msft_1-1623378589675.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@ritanoori 

 

Such a column should be created in Power Query. Not in DAX. One reason for this is optimization and compression.

Hi @Anonymous Thanks for the reply. I agree with you. However, I have one of the columns using lookupvalue which as my knolwedge can't be used in query. Do you suggest better solution? 

 

SH Number = LOOKUPVALUE (

    Fact_TMS_reports[SHIPMENT_NUMBER],

    Fact_TMS_reports[VOUCHER_ID],

    Fact_GL[PoNumber],

    "N/A"

)

Anonymous
Not applicable

Trust me, all you can do in DAX, you can do in Power Query and even more since the M language that PQ uses to do transformations of data is more powerful than DAX. Lookup tables in PQ are not even needed. To obtain what you want you can use joins, for instance, or functions that you then invoke in each row of a table. There are many ways in M/Power Query to achieve what you need.

amitchandak
Super User
Super User

@ritanoori , Try like


if([col2] = "N/A" && left([Col1],2) = "SH" && len([Col1]) =14 , [Col1], [Col2])

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.