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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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.LearnAndPractise(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.LearnAndPractise(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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.

Top Solution Authors