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

how to get value from a text column without a certain letter

Hi, I want to get a integer column baseed this column:

column

W+2

W-5
W-6

W

W+1

and expected result:

2

-5

-6

0

1

do you have any solutions?

2 ACCEPTED SOLUTIONS
SergioSilvaPT
Resolver V
Resolver V

Hi @Anonymous,

 

According with you sample data you only need to do the following steps in Power Query:

  1. Replace "W" with ""
  2. Replace "" with 0
  3. Change the type of data to whole number

 

 

Solution in DAX:

Add the following column:

 

Column =
IF('Table'[Data]="W",
    "0",
    REPLACE('Table'[Data],1,1,"")
)

 

 

Check the pbi in attach with an example.

 

Regards,
Sérgio Silva

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

Check out my blog for tips and tricks about Power BI: https://pbibits.wordpress.com/

View solution in original post

Ahmedx
Super User
Super User

 

 

ID = 
 VAR _табл. =
     ДОБАВИТЬ КОЛОННЫ (
         GENERATE (GENERATESERIES (1, 9, 1), VALUES (tbl[serial])),
         "я бы",
             ЕСЛИ ОШИБКА (
                 СТОИМОСТЬ (
                     IF (CONTAINSSTRING ([серийный номер], "-" ), "-" ) & MID ( [серийный номер], [значение], 1 )
                 ),
                 ПУСТОЙ ()
             )
     )
 VAR _Результат =
     СЦЕПИТЬ ( _tbl, [id], "" )
 ВОЗВРАЩАТЬСЯ
     ЕСЛИ (HASONEVALUE ('tbl'[serial]), ЕСЛИ (_Result = "", "0", _Result)) 

 

https://dropmefiles.com/WDG3S

View solution in original post

7 REPLIES 7
Ahmedx
Super User
Super User

 

 

ID = 
 VAR _табл. =
     ДОБАВИТЬ КОЛОННЫ (
         GENERATE (GENERATESERIES (1, 9, 1), VALUES (tbl[serial])),
         "я бы",
             ЕСЛИ ОШИБКА (
                 СТОИМОСТЬ (
                     IF (CONTAINSSTRING ([серийный номер], "-" ), "-" ) & MID ( [серийный номер], [значение], 1 )
                 ),
                 ПУСТОЙ ()
             )
     )
 VAR _Результат =
     СЦЕПИТЬ ( _tbl, [id], "" )
 ВОЗВРАЩАТЬСЯ
     ЕСЛИ (HASONEVALUE ('tbl'[serial]), ЕСЛИ (_Result = "", "0", _Result)) 

 

https://dropmefiles.com/WDG3S

Idrissshatila
Super User
Super User

Hello,

 

You could add a calculated column with this dax

 

Column = Var Column1 = RIGHT(customers[Customer Name],2)
var Column2 = LEN(customers[Customer Name])
return
IF(Column2 = 3,Column1,FORMAT(0,"0"))
 

If I answered your question, please mark my post as solution, Appreciate your Kudos👍

Follow me on Linkedin



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




Anonymous
Not applicable

Whatif the value is W+100 or W+1000, does any function can omit letter W?

SergioSilvaPT
Resolver V
Resolver V

Hi @Anonymous,

 

According with you sample data you only need to do the following steps in Power Query:

  1. Replace "W" with ""
  2. Replace "" with 0
  3. Change the type of data to whole number

 

 

Solution in DAX:

Add the following column:

 

Column =
IF('Table'[Data]="W",
    "0",
    REPLACE('Table'[Data],1,1,"")
)

 

 

Check the pbi in attach with an example.

 

Regards,
Sérgio Silva

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

Check out my blog for tips and tricks about Power BI: https://pbibits.wordpress.com/
Anonymous
Not applicable

This column is calculated use DAX, so powerquery does not work

@Anonymous , check my solution in DAX in the first response.

Regards,
Sérgio Silva

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

Check out my blog for tips and tricks about Power BI: https://pbibits.wordpress.com/
Ahmedx
Super User
Super User

in power query:

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\User\Desktop\serial.xlsx"), null, true),
    Лист1_Sheet = Source{[Item="Лист1",Kind="Sheet"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Лист1_Sheet,{{"Column1", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"serial", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "ID", each Number.From(Text.Select([serial],{"-"})&
Text.Select([serial],{"1".."9"}))??0)
in
    #"Added Custom"

 

https://dropmefiles.com/rT5IN

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.