Hirra Abdul Malik
Hirra Abdul Malik

Reputation: 13

Check if we have a new record next day

I have this tale:

ProductName Date
A 01.02.2020
B 01.02.2020
A 02.02.2020
B 02.02.2020
C 02.02.2020

I want to add a new column that is a binary column, showing 1 for a record that did not exist on a previous day.

For product C I should get 1 and for A and B - 0:

ProductName Date Flag
A 01.02.2020 0
B 01.02.2020 0
A 02.02.2020 0
B 02.02.2020 0
C 02.02.2020 1

Upvotes: 1

Views: 91

Answers (1)

ZygD
ZygD

Reputation: 24498

I see that for the absolute minimum date you do not want to return 1. In this case you could use this calculated column formula:

Flag = 
VAR _prod = [ProductName]
VAR _date = [Date]
VAR _prod_exists_day_ago = NOT(COUNTROWS(FILTER('TableName', [ProductName] = _prod && [Date] = _date-1)))
RETURN INT(IF([Date] <> MIN([Date]), _prod_exists_day_ago))

enter image description here

Upvotes: 1

Related Questions