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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
u4us1923
Frequent Visitor

Power Query subtract with replace

Hello

 

I'd like to subtract other figures from the total figure. then I'd like to replace the total value with the new value. how can I do this in Power Query?

u4us1923_1-1713134921089.png

 

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Design red flag. Do not repeat data in the same table.

 

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "i45WCskvScxR0oHThgYGSrE60UoBiUWZxUC+c2ZJJZAyBQv65Oel5OehiMYCAA==", 
          BinaryEncoding.Base64
        ), 
        Compression.Deflate
      )
    ), 
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [Column1 = _t, Column2 = _t, Column3 = _t]
  ), 
  #"Changed Type" = Table.TransformColumnTypes(
    Source, 
    {{"Column1", type text}, {"Column2", type text}, {"Column3", Int64.Type}}
  ), 
  #"Replaced Value" = Table.ReplaceValue(
    #"Changed Type", 
    each [Column3], 
    each 
      if [Column2] = "Total" then
        [Column3] - List.Sum(List.Skip(#"Changed Type"[Column3], 1))
      else
        [Column3], 
    Replacer.ReplaceValue, 
    {"Column3"}
  )
in
  #"Replaced Value"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

View solution in original post

2 REPLIES 2
u4us1923
Frequent Visitor

thank you.. Its work! 🙏

lbendlin
Super User
Super User

Design red flag. Do not repeat data in the same table.

 

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "i45WCskvScxR0oHThgYGSrE60UoBiUWZxUC+c2ZJJZAyBQv65Oel5OehiMYCAA==", 
          BinaryEncoding.Base64
        ), 
        Compression.Deflate
      )
    ), 
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [Column1 = _t, Column2 = _t, Column3 = _t]
  ), 
  #"Changed Type" = Table.TransformColumnTypes(
    Source, 
    {{"Column1", type text}, {"Column2", type text}, {"Column3", Int64.Type}}
  ), 
  #"Replaced Value" = Table.ReplaceValue(
    #"Changed Type", 
    each [Column3], 
    each 
      if [Column2] = "Total" then
        [Column3] - List.Sum(List.Skip(#"Changed Type"[Column3], 1))
      else
        [Column3], 
    Replacer.ReplaceValue, 
    {"Column3"}
  )
in
  #"Replaced Value"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.