Refactor similar queries but reverse side of inequality operator How can I refactor this?

public static IQueryable&lt;T_COMPANY&gt; WhereTotalTransactionOrShowCaseAtLeast(this IQueryable&lt;T_COMPANY&gt; query, int minimum, DateTime? date = null)
{
    if (date == null)
    {
        query = query.Where(company =&gt; (company.Products.Count + company.References.Count) &gt;= minimum ||
                                     ( (company.T_RFQs.Count + company.T_POs.Count + company.T_INVOICEs.Count) &gt;= minimum) );
        return query;
    }
    else
    {
        var notNullDate = date.Value;

        var result = (from company in query
                      let rfqCount = company.T_RFQs.Count(item =&gt; item.create_date &lt;= notNullDate)
                      let poCount = company.T_POs.Count(item =&gt; item.create_date &lt;= notNullDate)
                      let invoiceCount = company.T_INVOICEs.Count(item =&gt; item.create_date &lt;= notNullDate)
                      let productCount = company.Products.Count(item =&gt; item.create_date &lt;= notNullDate)
                      let referenceCount = company.References.Count(item =&gt; item.create_date &lt;= notNullDate)
                      where (rfqCount + poCount + invoiceCount) &gt;= minimum || (productCount + referenceCount) &gt;= minimum
                      select company);

        return result;
    }

}

public static IQueryable&lt;T_COMPANY&gt; WhereTotalTransactionOrShowCaseLessThan(this IQueryable&lt;T_COMPANY&gt; query, int minimum, DateTime? date = null)
{
    if (date == null)
    {
        query = query.Where(company =&gt; (company.Products.Count + company.References.Count) &gt;= minimum ||
                                     ((company.T_RFQs.Count + company.T_POs.Count + company.T_INVOICEs.Count) &lt; minimum));
        return query;
    }
    else
    {
        var notNullDate = date.Value;

        var result = (from company in query
                      let rfqCount = company.T_RFQs.Count(item =&gt; item.create_date &lt;= notNullDate)
                      let poCount = company.T_POs.Count(item =&gt; item.create_date &lt;= notNullDate)
                      let invoiceCount = company.T_INVOICEs.Count(item =&gt; item.create_date &lt;= notNullDate)
                      let productCount = company.Products.Count(item =&gt; item.create_date &lt;= notNullDate)
                      let referenceCount = company.References.Count(item =&gt; item.create_date &lt;= notNullDate)
                      where (rfqCount + poCount + invoiceCount) &gt;= minimum || (productCount + referenceCount) &lt; minimum
                      select company);

        return result;
    }

}
From what I can understand you are looking for a way to consolidate this code into one function and specify that the comparrison with minimum can either be less than or greater than or equal to. You could try something like this

public static IQueryable&lt;T_COMPANY&gt; WhereTotalTransactionOrShowCaseAtLeast(this IQueryable&lt;T_COMPANY&gt; query, int minimum, DateTime? date = null)
    {
        WhereTotalTransactionWithCompare(query, minimum, (x, min) =&gt; x &gt;= min, date);
    }


    public static IQueryable&lt;T_COMPANY&gt; WhereTotalTransactionOrShowCaseLessThan(this IQueryable&lt;T_COMPANY&gt; query, 
                                                                                    int minimum, 
                                                                                    DateTime? date = null)
    {
        WhereTotalTransactionWithCompare(query, minimum, (x, min) =&gt; x &lt; min, date);

    }

    public static IQueryable&lt;T_COMPANY&gt; WhereTotalTransactionWithCompare(this IQueryable&lt;T_COMPANY&gt; query,
                                                                                    int minimum,
                                                                                    Func&lt;int, int bool&gt; compareToMinimum,
                                                                                    DateTime? date = null)
    {
        if (date == null)
        {
            query = query.Where(company =&gt; (company.Products.Count + company.References.Count) &gt;= minimum ||
                                         (comparer(company.T_RFQs.Count + company.T_POs.Count + company.T_INVOICEs.Count, minimum)));
            return query;
        }
        else
        {
            var notNullDate = date.Value;

            var result = (from company in query
                          let rfqCount = company.T_RFQs.Count(item =&gt; item.create_date &lt;= notNullDate)
                          let poCount = company.T_POs.Count(item =&gt; item.create_date &lt;= notNullDate)
                          let invoiceCount = company.T_INVOICEs.Count(item =&gt; item.create_date &lt;= notNullDate)
                          let productCount = company.Products.Count(item =&gt; item.create_date &lt;= notNullDate)
                          let referenceCount = company.References.Count(item =&gt; item.create_date &lt;= notNullDate)
                          where (rfqCount + poCount + invoiceCount) &gt;= minimum || comparer(productCount + referenceCount, minimum)
                          select company);

            return result;
        }

    }