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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Create a new column by group

I have a dataframe like this

groupcountrytypevalue
ajapan AB1000
ajapan - ACAB500
aMexico - ACCD630
aUSAAB1400
bjapan CD1000
bjapan - ACCD0
bUSA - ACAB0
bUSA- ACCD0
bMexicoAB1500
aUSA - ACCD6000
aUSA- ACAB4000

 

And I would to create a new column removing AC in column country, because after I want sum value of Japan and Japan - AC, for example. The result would be like this

 

groupcountrytypevaluecountry  2
ajapan AB1000japan
ajapan - ACAB500japan
aMexico - ACCD630Mexico
aUSAAB1400USA
bjapan CD1000japan
bjapan - ACCD0japan
bUSA - ACAB0USA
bUSA- ACCD0USA
bMexicoAB1500Mexico
aUSA - ACCD6000USA
aUSA- ACAB4000USA
2 ACCEPTED SOLUTIONS
AlienSx
Super User
Super User

    Table.AddColumn(
        Source, "Custom", 
        each Text.Trim(
            if Text.EndsWith([country], "- AC") 
            then Text.Range([country], 0, Text.Length([country]) - 4) 
            else [country]
        )
    )

View solution in original post

ThxAlot
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUcpKLEjMUwAyHJ2AhKGBgYFSrA6ylIKugqMzTN4USdo3tSIzOR8m7ewCJMyMEdKhwY5wU02g2pKQLQTrgFuIkEI2ECEHNA7FJSgy2LVAHAh3BLLbkUyDONwAVRLZJhOwXCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [group = _t, country = _t, #"type" = _t, value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"group", type text}, {"country", type text}, {"type", type text}, {"value", Int64.Type}}),
    #"Extracted country" = Table.TransformColumns(#"Changed Type", {"country", each Text.Trim(Text.BeforeDelimiter(_,"-"))})
in
    #"Extracted country"

ThxAlot_0-1701719517502.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

2 REPLIES 2
ThxAlot
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUcpKLEjMUwAyHJ2AhKGBgYFSrA6ylIKugqMzTN4USdo3tSIzOR8m7ewCJMyMEdKhwY5wU02g2pKQLQTrgFuIkEI2ECEHNA7FJSgy2LVAHAh3BLLbkUyDONwAVRLZJhOwXCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [group = _t, country = _t, #"type" = _t, value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"group", type text}, {"country", type text}, {"type", type text}, {"value", Int64.Type}}),
    #"Extracted country" = Table.TransformColumns(#"Changed Type", {"country", each Text.Trim(Text.BeforeDelimiter(_,"-"))})
in
    #"Extracted country"

ThxAlot_0-1701719517502.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



AlienSx
Super User
Super User

    Table.AddColumn(
        Source, "Custom", 
        each Text.Trim(
            if Text.EndsWith([country], "- AC") 
            then Text.Range([country], 0, Text.Length([country]) - 4) 
            else [country]
        )
    )

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors