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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Oros
Post Prodigy
Post Prodigy

Create a new column, extract

Hello,

 

I have a payment terms column. How do I create a column based on the payment terms column to show the percentage if available, if no percentage available, then put zero as the value.  Thanks.

 

Oros_0-1718918814338.png

 

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

Thanks for the reply from @vicky_ , please allow me to provide another insight:

 

Hi @Oros ,

 

If you want to achieve the result with calculated column, you can try below formula and change [result] column type by whole number.

result = 
VAR Terms = 'PaymentTerms'[TERMS]
VAR PercentPosition =
    SEARCH ( "%", Terms, 1, LEN ( Terms ) )
VAR SpacePosition =
    SEARCH ( "S", Terms, 1, LEN ( Terms ) )
RETURN
    IF (
        CONTAINSSTRING ( PaymentTerms[TERMS], "%" ),
        MID (
            PaymentTerms[TERMS],
            SpacePosition + 1,
            PercentPosition - SpacePosition - 1
        ),
        "0"
    )

vkongfanfmsft_0-1718954875211.png

 

Best Regards,
Adamk Kong

 

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-kongfanf-msft
Community Support
Community Support

Thanks for the reply from @vicky_ , please allow me to provide another insight:

 

Hi @Oros ,

 

If you want to achieve the result with calculated column, you can try below formula and change [result] column type by whole number.

result = 
VAR Terms = 'PaymentTerms'[TERMS]
VAR PercentPosition =
    SEARCH ( "%", Terms, 1, LEN ( Terms ) )
VAR SpacePosition =
    SEARCH ( "S", Terms, 1, LEN ( Terms ) )
RETURN
    IF (
        CONTAINSSTRING ( PaymentTerms[TERMS], "%" ),
        MID (
            PaymentTerms[TERMS],
            SpacePosition + 1,
            PercentPosition - SpacePosition - 1
        ),
        "0"
    )

vkongfanfmsft_0-1718954875211.png

 

Best Regards,
Adamk Kong

 

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

 

 

Hi @v-kongfanf-msft ,

 

Thank you for for help.  It looks fine but just getting that small error that I could not figure out.  Thanks again.

 

Oros_2-1718979428895.png

 

Hi @Oros ,

 

Based on the description of the error message, please check the data column classes of the columns referenced in the mid function to make sure they are all of type text.

 

related document:

MID function (DAX) - DAX | Microsoft Learn

 

Best Regards,
Adamk Kong

 

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

vicky_
Super User
Super User

vicky__0-1718924485171.png

This can be done in Power Query (assuming that the format of your data is SOMETHING space number%)

First part is to extract the number part by going to Add Column > Extract > Text between Delimiters

Then you convert the column to a Whole Number, this will result in some errors. For the errors (i.e if there's no percentage), you can go to Transform > Replace Values > Replace Errors to make them 0.

Hi @vicky_ ,

 

Thank you very much for your quick reply.  It looks like just a little bit of tweak will bring the desired result.  I am still NOT getting the actual number that is attached or equivalent to the percentage.  Any ideas?  Thanks again.

 

Here are the details:

Oros_0-1718979013026.png

 

Oros_1-1718979085247.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.