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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Need help to select different character length using calulate

Hi All
I have the measure below that works correctly but need help to select all the part_no in the table, in which the character length ranges from 4 to 21 . As you can see I started off with Len=7. How do I format the measure below to look at all the parts_no that has a Len from 4 to 21.
 

P360PN = VAR AA =

    LEN( [part_no] )

VAR BB =

    CALCULATE(FIRSTNONBLANK('P360'[Primary Item Number], 1), FILTER(ALL('P360'),'P360'[Engineering Item Number]= 'cqms_mnc_data_v'[part_no] ) )

RETURN

    IF( AA = 7, [part_no], BB )

6 REPLIES 6
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, in my understanding, you want to remove all 0 after a number, if this is the case, here's my solution.

1. In Power Query, change the column data type to Text.

2. Create three custom columns.

vkalyjmsft_0-1646127429767.png

Custom = Text.Reverse([part_no])
Custom.1 = Text.Trim([Custom],"0")
Custom.2 = Text.Reverse([Custom.1])

Then remove unwanted columns, get the result.

vkalyjmsft_1-1646127669725.png

I attach the sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

 

UPDATE: I would use "00" to make this a bit more precise - @Anonymous are there any part numbers that end in 00 where you want to keep the 00?

 

 

@v-yanjiang-msft  You don't need the reverse steps in here.

 

@Anonymous  Is it just 0s at the end of your part numbers that you need to remove? Is there ever a 0 at the end that needs to stay? if so, we'll need more info about how to know what to keep.

 

However, if you always want to remove the leading and trailing zeros, then as @v-yanjiang-msft  suggested, in Power Query you can add a custom column to Trim the 0s from your Part_no that comes from the system. Does that make sense?


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

AllisonKennedy
Super User
Super User

@Anonymous  You can use the && for and filter, which will give you between:

 

P360PN = VAR AA =

    LEN( [part_no] )

VAR BB =

    CALCULATE(FIRSTNONBLANK('P360'[Primary Item Number], 1), FILTER(ALL('P360'),'P360'[Engineering Item Number]= 'cqms_mnc_data_v'[part_no] ) )

RETURN

    IF( AA <= 21 && AA >= 4, [part_no], BB )


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

@AllisonKennedy 

The measure work but didnt give me the desire result like the orginal measure. With my orginal measure the dsire reult was correctl as i needed the measure  as i needed to pull in the primary item number info as seen below in the table using the length of 7

bu965_2-1645800371269.png

bu965_6-1645801205880.png

When I use the  updated measure using  IF( AA <= 21 && AA >= 4, [part_no], BB ). I get the following but not the correct  as the P360PN should be 3017993

bu965_8-1645801332101.png

 

bu965_5-1645801144014.png

 

 

 

 

@Anonymous It looks like your measure for [part_no] needs fixed in this case. What is the DAX for part_no please and how do you know you want to exclude the last 2 zeros?

 

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

Hi @AllisonKennedy 

The part_no is comming from our coporate system and cannot change the raw data. Some part_no coming from the coprate system will have 00 on the end and the same part number might be put in without the 00 when data the part number is selected. I hope this help. Let me know if you need more clarity

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.