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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors