{{ transformations:TrimByConditionAction.png}}
====== TRIM TABLE BY CONDITION ======
Category: Transform / Filters\\

\\ 
=====Description=====
This action removes the rows above or below the first row where the specific [[syntax:start|condition]] is true.\\

\\
=====Use cases=====
  *Remove records that occurred before or after a specific date.
  *Remove records of system events that happened before an error occurred, keeping the events that happened //after// the error.
  *Determine the effect of a sale by removing sales data prior to the sale and focusing on the post-sale data.
  *Remove rows after a specific situation occurs, keeping the steps that happened //leading up to// the situation.

\\ 
=====Action settings=====
^Setting ^Description ^
|Condition|Enter an expression that evaluates to TRUE or FALSE.|
|Delete rows that are|Select whether the rows above or below the first match are removed.  Options: //Above first match// or //Below\\ first match//.|
|Delete first matching row too|When checked, the first row that satisfies the //Condition// is removed as well as the rows above/below it.|

\\ 
=====Examples=====

====Example #1====
>Remove the rows with Montreal sales.\\

===Before (source table)===
^ Store/ City  ^Jan-15  ^Feb-15  ^
| St#1-Montreal  |  30359|  35018|
| St#2-Montreal  |  24500|  28251|
| Total Montreal  |  87580|  97569|
| St#1-Toronto  |  29800|  33691|
| St#2-Toronto  |  37464|  40250|
| Total Toronto  |  108502|  119331|

===After (result table)===
^Store/ City  ^Jan-15  ^Feb-15  ^
|**St#1-Toronto**  |  **29800**|  **33691**|
|**St#2-Toronto**  |  **37464**|  **40250**|
|**Total Toronto**  |  **108502**|  **119331**|

===Action parameters===
> Condition: [Store/City]="Total Montreal"
> Delete rows that are: Above first match
> Delete the first matching row too

\\
====Example #2====
>Remove records after the system error occurred to focus on the steps that may have caused it.\\

===Before (source table)===
^Timestamp ^Log Message ^
|10:00 AM  |System Start  |
|10:05 AM  |User Login  |
|10:10 AM  |Database Connected  |
|10:15 AM  |ERROR: Connection Lost  |
|10:20 AM  |Retrying Connection  |

===After (result table)===
^Timestamp ^Log Message ^
|**10:00 AM**  |**System Start**  |
|**10:05 AM**  |**User Login**  |
|**10:10 AM**  |**Database Connected**  |
|**10:15 AM**  |**ERROR: Connection Lost**  |

===Action parameters===
> Condition: [Log Message]="ERROR: Connection Lost"
> Delete rows that are: Below first match


\\ 
=====Community examples=====
  * [[https://community.easymorph.com/t//2267/1|How to parse EDI file (e.g. X12 transaction set 837)]] ([[https://community.easymorph.com/uploads/short-url/6tzpyfamtKPeOq37FyUjBxKud4F.morph|Project]]; Module: //Main//; Group: //Header//; Table: //Raw header//; Action position: //2//)
  * [[https://community.easymorph.com/t//2267/1|How to parse EDI file (e.g. X12 transaction set 837)]] ([[https://community.easymorph.com/uploads/short-url/6tzpyfamtKPeOq37FyUjBxKud4F.morph|Project]]; Module: //Main//; Group: //Raw EDI//; Table: //Raw EDI X12//; Action position: //5//)
  * [[https://community.easymorph.com/t//2711/2|My first experiment API + conditional workflow + iteration]] ([[https://community.easymorph.com/uploads/short-url/jG4qopOtRfSxDo0UFJkNbBaKvac.morph|Project]]; Module: //Main//; Group: //Acquisition data via API//; Table: //Data from API//; Action position: //5//)

\\ 
=====See also=====
  * [[transformations:keepremovematching|Keep/remove matching]]
  * [[transformations:trimtable|Trim table]]