Forum Discussion

Ria's avatar
Ria
Frequent Visitor
8 years ago
Solved

Create a filtered table with an if statement

I need to account for two exceptions in my Sales data by creating a separate table.     1. When a credit/rebill is done to change the client code of the bill.  This causes the data to have the same...
  • Ria's avatar
    Ria
    8 years ago

    This solution was a good start but the data was more complex than originally anticipated.  More filters were required.  The final solution was to add 2 more columns 

    Min Acct = if(Sales[ACCT_CODE] = CALCULATE(MIN(Sales[ACCT_CODE]),ALLEXCEPT(Sales,Sales[BILL_NUMBER],Sales[DOCUMENT_TYPE])),"yes","no")

     

    CURRENT INV = IF(CALCULATE(MAX(Sales[DOCUMENT_TYPE]),ALLEXCEPT(Sales,Sales[WO NUM])) = "REBILL", "REBILL",iF(CALCULATE(MIN(Sales[DOCUMENT_TYPE]),ALLEXCEPT(Sales,Sales[WO NUM])) = "CREDIT","CREDIT","INVOICE"))

     

    and then to create the table

     

    Customer WO = SELECTCOLUMNS(filter(  sales,sales[DOCUMENT_TYPE]= Sales[CURRENT INV] && Sales[CREATED_TIME] = Sales[Column] && Sales[Min Acct] = "yes" ), "WO NUMBER", Sales[WO NUM], "CLIENT", Sales[CLIENT],"CREATED TIME", Sales[CREATED_TIME])

     

    This works except for one condition.  When there is an "A", "P" or "E" bill and there is a CREDIT/REBILL invoice.  Only a very small percentage of invoices fall in this category, so the solution is acceptable.