Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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

 

 

1 ACCEPTED SOLUTION

Attached below is the PBIX if it helps.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi,

check out this support article from Microsoft, it can lead you somewhere near a solution.

https://docs.microsoft.com/en-us/dax/date-and-time-functions-dax

 

Regards,

Lewis

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])
)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Attached below is the PBIX if it helps.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Sorry, trying to paste that into the code windows was giving me some kind of wonky error.

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

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


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler 

 

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

 

Thank you,

Melisa

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.