Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

How to keep only first row of a column?

Aviator0807
8 - Asteroid

What I have right now

MonthYearSalesStore
April2021$$$0478
April2021$$$0631
April2021$$$0512
April2021$$$0154

 

What I would like is 

MonthYearSalesStore
April2021$$$0478
  $$$0631
  $$$0512
  $$$0154
5 REPLIES 5
mst3k
11 - Bolide

a multi row formula tool could do this, the formula for Month for example would be:

 

if [Month]=[Row-1:Month] then null() else [Month] endif

 

then repeat that for the Year column. you'll need to make sure your data is sorted the way you want it..

AngelosPachis
16 - Nebula

Hi @Aviator0807 ,

 

Here's one way that you can do it

 

AngelosPachis_0-1632341053953.png

 

You form the date field in the first formula tool and then check if the date repeats itself with the previous row, so you only keep the first occurrence.

 

Hope that helps,

Angelos

Aviator0807
8 - Asteroid

@mst3k I tried that but wasnt getting the result I need.

 

This is what I was getting when I used that. 

 

 

MonthYearSalesStore
April2021$$$0487
  $$$0235
April2021$$$0951
  $$$0520
April2021$$$0874
AngelosPachis
16 - Nebula

@mst3k suggestion should work if you create new fields with the multi-row formula tools, and then replace the old ones with a select tool

 

AngelosPachis_0-1632344335795.png

 

The issue that may arise with this approach though @Aviator0807  is that in case you have the same month but different years stacked on top of each other, that expressions will not address that change in year, as show below

 

AngelosPachis_1-1632344412514.png

 

Ideally this is why you should form a date field as proposed in my first post and then probably group by that field in the multi-row formula tool, before creating the logic.

 

ncrlelia
11 - Bolide

Hi @Aviator0807

 

I would suggest to create an ID for each group of data so that it is easier to follow through.

Assuming that your group is defined by Month and Year,

 

  1. Use Multi-Row formula to create ID field
    • ncrlelia_0-1632380673447.png

       

  2. Use a formula tool to keep current Month and Year value if ID = 1.
    • I've set Year to String so that I can use Multi-Field formula. You can simply write 2 formula using the Formula tool for Month and Year separately, if your Year has to be Numeric 
    • ncrlelia_1-1632380834912.png

Hope this helps.

 

Cheers,

Lelia

Labels