Forum Discussion

JohnJairoV's avatar
JohnJairoV
Helper I
9 years ago
Solved

non negative values in difference between date columns in PowerQuery

Hi to all!   I have this data (the letters in first row and numbers in first column are just for refference):     A B C D E F G H I 1 Other Date Cont Date 1 Cont Date 2 Cont Da...
  • ImkeF's avatar
    9 years ago

    You can basically use the same style when addiing column like this:

    For Result1:

     

    List.Max({	#duration(0,0,0,0),
    List.Min({[Cont Date 1],[Cont Date 2],[Cont Date 3]}) - [Other Date]
    })

    And for Result2:

     List.Max({	#duration(0,0,0,0),
    List.Min({[Prop Date 1],[Prop Date 2],[Prop Date 3]})-List.Max({[Cont Date 1],[Cont Date 2],[Cont Date 3]})
    })

    You create lists as your "ranges" to choose from and then you can use List.Min or List.Max as the equivalent to MIN or MAX in Excel.

    To create a list, you wrap your comma-separated elements into curly brackets: { FirstElement, SecondElement... }

    Also you have to format the first 0 as a duration for the formula to work properly.

  • ImkeF's avatar
    ImkeF
    9 years ago

    Not so elegant any more then:

     

    = Table.AddColumn(#"Added Custom", "Custom.1", each try if List.Max({null,
    		List.Min({[Prop Date 1],[Prop Date 2],[Prop Date 3]})-List.Max({[Cont Date 1],[Cont Date 2],[Cont Date 3]})
    	  }) > #duration(0,0,0,0) then List.Max({null,
    		List.Min({[Prop Date 1],[Prop Date 2],[Prop Date 3]})-List.Max({[Cont Date 1],[Cont Date 2],[Cont Date 3]})
    	  }) else 0 otherwise null)