Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

DAX Formula for Assign Date

Hi,

 

I would like to retrieve the assign date by following the below conditions:

1)  for the first month of the record, to retrieve as assign date - the first occurrence/date of the record in that month

2)  starting with the second month, if the record had appeared in the previous month at least one time AND if it IS present in the first day of the second month, to retrieve as assign date - the first occurrence/date of the record in that month

OR

2) starting with the second month, if the record had appeared in the previous month at least one time AND if was NOT present in the first day of the second month, to retrieve as assign date for the second month - the first occurrence/date of the record in the second month

This process is being repeated for all months, by having in mind the first day of the month.

I have the below sample, with the AssignDate that needs to be retrieved.

 

If anything, please let me know.

Many thanks,

Melisa

 

recordMonthDateAssignDate
1244333March3/5/20203/5/2020
1244333March3/15/20203/5/2020
1244333March3/25/20203/5/2020
1244333April4/1/20203/5/2020
1244333April4/5/20203/5/2020
1344222March3/3/20203/3/2020
1344222March3/9/20203/3/2020
1344222April4/5/20204/5/2020
1344222May5/1/20204/5/2020

 

 

6 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    So is your example data provided below minus the AssignDate column and the AssignDate is what you want as the output?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Greg_Deckler 

       

      Yes, the last column is in fact the Output column.

       

      Thank you,

      Melisa

    • Greg_Deckler's avatar
      Greg_Deckler
      Community Champion

      Create this column:

      MonthNum = MONTH([Date])

      and then this column:

      AssignDate =
      VAR __FirstMonth = MINX(FILTER('Data','Data'[record] = EARLIER('Data'[record])),[MonthNum])
      VAR __FirstDate = MINX(FILTER('Data','Data'[record] = EARLIER('Data'[record]) && [MonthNum] = __FirstMonth),[Date])
      VAR __CurrentMonthDate = MINX(FILTER('Data','Data'[record] = EARLIER('Data'[record]) && 'Data'[MonthNum] = EARLIER('Data'[MonthNum])),'Data'[Date])
      VAR __WhoseOnFirst = IF(__CurrentMonthDate = DATE(YEAR(__CurrentMonthDate),MONTH(__CurrentMonthDate),1),TRUE(),FALSE())
      RETURN
      SWITCH(TRUE(),
      [MonthNum] = __FirstMonth,__FirstDate,
      __WhoseOnFirst && __FirstMonth = [MonthNum] - 1,__FirstDate,
      MINX(FILTER('Data','Data'[record] = EARLIER('Data'[record]) && [MonthNum] <> __FirstMonth),[Date])
      )

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion
        Sorry, trying to paste that into the code windows was giving me some kind of wonky error.