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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Help with grouping modified date into today, yesterday etc.

Sorry if I've already posted this but can't find my original post!

 

I'm trying to group my datetime column "modify time" so it contains data like this:

 

New column name: Last Modified

Today: 4

Yesterday: 7

2 days ago: 3

3 days ago: 4

 

I have the datetime column but I also have "Modified Date" which is a date column to work with.

 

I'm struggling with the statement, I assume I want something like this:

 

IF [Modified Date] =  TODAY THEN "Today" ELSE IF [Modified Date] > TODAY -1 AND < TODAY THEN "Yesterday" etc.

 

Any help would be greatly appreciated!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Not sure if it's the most elegant solution but I went with this in the end:

 

Last Modified =
IF('sysaid'[Modified Date]=TODAY(),"0 Days",
IF('sysaid'[Modified Date]= TODAY()-1,"1 Day Ago",
IF('sysaid'[Modified Date]= TODAY()-2, "2 Days Ago",
IF('sysaid'[Modified Date]= TODAY()-3, "3 Days Ago",
IF('sysaid'[Modified Date]= TODAY()-4, "4 Days Ago",
IF('sysaid'[Modified Date]= TODAY()-5, "5 Days Ago",
IF('sysaid'[Modified Date]= TODAY()-6, "6 Days Ago",
IF( 'sysaid'[Modified Date] <= TODAY()-7, "Over A Week") )))))))

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , In you date table create a column like this

Date Type = SWITCH(TRUE(),'Date'[Date]=TODAY(),"Today"
,'Date'[Date]=TODAY()-1,"Yesterday"
,'Date'[Date]=TODAY()-2,"2 Days Ago"
,'Date'[Date]&"")

Sort it on Date

 

Join it date of date table with date of your table

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

@amitchandak  Thank you, I think this would only work if I was to continue with 3,4,5,6 days etc. but I'd like to expand the range the older the data is so for example last week, last month which I don't think can be done with a switch? I'd need to use an IF statement to achieve this- Is that correct?

Hi @Anonymous ,

 

Try to create the column.

Column = var diff = DATEDIFF('Table (2)'[Modified Date],TODAY(),DAY)
return SWITCH(TRUE(),
            diff<7,diff&" days ago",
            7<=diff&&diff<30,TRUNC(diff/7)&" weeks ago",
            diff>=30,TRUNC(diff/30)&" months ago")

V-lianl-msft_0-1598422563362.png

 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Not sure if it's the most elegant solution but I went with this in the end:

 

Last Modified =
IF('sysaid'[Modified Date]=TODAY(),"0 Days",
IF('sysaid'[Modified Date]= TODAY()-1,"1 Day Ago",
IF('sysaid'[Modified Date]= TODAY()-2, "2 Days Ago",
IF('sysaid'[Modified Date]= TODAY()-3, "3 Days Ago",
IF('sysaid'[Modified Date]= TODAY()-4, "4 Days Ago",
IF('sysaid'[Modified Date]= TODAY()-5, "5 Days Ago",
IF('sysaid'[Modified Date]= TODAY()-6, "6 Days Ago",
IF( 'sysaid'[Modified Date] <= TODAY()-7, "Over A Week") )))))))

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.