title: Power query conditional max min date
body: <p>I'm using PowerQuery 2013, and I'm new to it. </p>
  
  <p>Here is a sample of my data:</p>
  
  <p><img src="https://i.stack.imgur.com/nqiza.png" alt="need to remove yellow rows"></p>
  
  <p>I need to crop the dates in Power Query, on market level, to include only overlapping range of dates (can't just delete rows with nulls - it's OK to have nulls inside data range).</p>
  
  <p>I have found a number of articles to use functions but I'm just not good enough to adapt them to my situation. </p>
  
  <p>I tried to create a function (called MaxDate) and then create a column in my data invoking this function: </p>
  
  <p>MaxDate function query:</p>
  
  <pre><code>(table as table, mkt as text) =&gt; Table.Max(Table.SelectRows(table, [Market]=mkt))[Date]
  </code></pre>
  
  <p>Invoke the function in a new column:</p>
  
  <pre><code>= Table.AddColumn(Sales, "GetMaxDate", each MaxDate(Sales, [Market])[Date])
  </code></pre>
  
  <p>This returned "Error" and I can't resolve it. I was going to generate min/max date columns, and then filter out dates that fell outside as a final output. </p>