Forum Discussion

bhelou's avatar
bhelou
Responsive Resident
6 years ago
Solved

Subtract days power query BI

HI ,

 

Please i need to subtract 10 days from this function as attached , please anyone can help me with the formula .

 

=if[Day 2]="0" then [Last INV Date] - 10 else [Last INV Date]

 

"0" is the value of what i want to subtract 10 days of

Thanks,

 

 

  • I believe you want Date.AddDays([Last INV Date], -10)

     

    Here is an example query I created:

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLUN9Q3MjAyUIrViVYyAAoYIQsYAQWM4QKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Item = _t, #"Last INV Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Last INV Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Item] = "0" then Date.AddDays([Last INV Date],-10) else [Last INV Date])
    in
    #"Added Custom"



  • Hi bhelou 

     

    Try this.

     

    if [Day 2]="0" then Date.AddDays(  [Last INV Date], -10 ) else [Last INV Date]

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    LinkedIn


     

  • Hello bhelou 

     

    the value is a number, non a text. so use this formula

    if [Day 2]=0 then Date.AddDays( [Last INV Date], -10 ) else [Last INV Date]

     

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy

6 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    I believe you want Date.AddDays([Last INV Date], -10)

     

    Here is an example query I created:

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLUN9Q3MjAyUIrViVYyAAoYIQsYAQWM4QKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Item = _t, #"Last INV Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Last INV Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Item] = "0" then Date.AddDays([Last INV Date],-10) else [Last INV Date])
    in
    #"Added Custom"

  • Mariusz's avatar
    Mariusz
    Community Champion


    Hi bhelou 

     

    Try this.

     

    if [Day 2]="0" then Date.AddDays(  [Last INV Date], -10 ) else [Last INV Date]

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    LinkedIn


     

    • bhelou's avatar
      bhelou
      Responsive Resident

      Dear Mariusz ,

       

      The formula not is working it is givving me data but not subtracting at all , it is remaining the same ,

       

      if [Day 2]="0" then Date.AddDays( [Last INV Date], -10 ) else [Last INV Date]

       

      Attached image ,

      Many Thanks ,

       

       

      • Jimmy801's avatar
        Jimmy801
        Community Champion

        Hello bhelou 

         

        the value is a number, non a text. so use this formula

        if [Day 2]=0 then Date.AddDays( [Last INV Date], -10 ) else [Last INV Date]

         

        If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
        Kudoes are nice too

        Have fun

        Jimmy