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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Yas123
Regular Visitor

Dax Column creation based on latest date

Hello,

I am new to power bi and need some help. I am trying to create a column based on last login date. If the last login date is within a month ago, called active. If it is 2 months ago, called two months ago etc. 

Here is my dax but it’s showing the wrong result except for "Active".

Column = 

       IF( MONTH(TODAY())-1 <= MONTH((DATEADD(Employee[Last Login],-1,MONTH))), "Active",

       IF( MONTH(TODAY())-2 <= MONTH((DATEADD(Employee[Last Login],-2,MONTH))), "2months ago",

       IF( MONTH(TODAY())-3 <= MONTH((DATEADD(Employee[Last Login],-3,MONTH))), "3months ago",

       IF( MONTH(TODAY())-6 <= MONTH((DATEADD(Employee[Last Login],-6,MONTH))), "6months ago",

       IF( MONTH(TODAY())-12 <= MONTH((DATEADD(Employee[Last Login],-12,MONTH))), "Inactive")))))

 

1 ACCEPTED SOLUTION
StefanoGrimaldi
Resident Rockstar
Resident Rockstar

hre the reference in the formula: 

https://learn.microsoft.com/en-us/dax/datediff-function-dax

try somehting like this: 

Column = 

       IF( DATEDIFF ( StartDate, EndDate, MONTH ) <= 1 , "Active",

       IF( DATEDIFF ( StartDate, EndDate, MONTH ) <= 2, "2months ago",

       IF( DATEDIFF ( StartDate, EndDate, MONTH ) <= 3, "3months ago",

       IF( DATEDIFF ( StartDate, EndDate, MONTH ) < 12, "6months ago",

       IF( DATEDIFF ( StartDate, EndDate, MONTH ) >= 12, "Inactive")))))





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Yas123
Regular Visitor

Thank you so much💖

StefanoGrimaldi
Resident Rockstar
Resident Rockstar

hre the reference in the formula: 

https://learn.microsoft.com/en-us/dax/datediff-function-dax

try somehting like this: 

Column = 

       IF( DATEDIFF ( StartDate, EndDate, MONTH ) <= 1 , "Active",

       IF( DATEDIFF ( StartDate, EndDate, MONTH ) <= 2, "2months ago",

       IF( DATEDIFF ( StartDate, EndDate, MONTH ) <= 3, "3months ago",

       IF( DATEDIFF ( StartDate, EndDate, MONTH ) < 12, "6months ago",

       IF( DATEDIFF ( StartDate, EndDate, MONTH ) >= 12, "Inactive")))))





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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