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
rogerdea
Helper IV
Helper IV

Measure for net gain/loss

Hello, i'm trying to calculate the net gain or loss using two different date columns.  One column is 'join date' and the other is called 'leave date'.  Join date always has a value and leave date might not if someone is still active.

 

I'm not sure how to do this in DAX as i need to COUNT distinct ID's, for both date columns and then calculate the difference between each yearly value:

net2.JPG

 

Any ideas?

thanks

 

 

1 ACCEPTED SOLUTION
harshnathani
Community Champion
Community Champion

Hi @rogerdea ,

 

You will need to unpivot the columns JoinDate and LeaveDate.

 

1.jpg

 

 

Click on Unpivot Columns

 

2.JPG

 

 

 

After unpivoting your table will look like below.

 

 

3.JPG

 

Create a Calculated Column

 

Year = YEAR('Table'[Date])
 
 
Create a Measure

 

Net Gain/Loss =

var _DistinctCount_Joining_by_year = CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER('Table','Table'[Join/Leave] = "JoinDate"))

var _DistinctCount_Leave_by_year = CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER('Table','Table'[Join/Leave] = "LeaveDate"))

RETURN

_DistinctCount_Joining_by_year -_DistinctCount_Leave_by_year

4.JPG

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

View solution in original post

2 REPLIES 2
harshnathani
Community Champion
Community Champion

Hi @rogerdea ,

 

You will need to unpivot the columns JoinDate and LeaveDate.

 

1.jpg

 

 

Click on Unpivot Columns

 

2.JPG

 

 

 

After unpivoting your table will look like below.

 

 

3.JPG

 

Create a Calculated Column

 

Year = YEAR('Table'[Date])
 
 
Create a Measure

 

Net Gain/Loss =

var _DistinctCount_Joining_by_year = CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER('Table','Table'[Join/Leave] = "JoinDate"))

var _DistinctCount_Leave_by_year = CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER('Table','Table'[Join/Leave] = "LeaveDate"))

RETURN

_DistinctCount_Joining_by_year -_DistinctCount_Leave_by_year

4.JPG

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

speedramps
Super User
Super User

Hi roger

 

Why does 1212, 2099 and 1313 rejoin in overlapping periods and how do you want these overlaps counted please?

 

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.

Top Solution Authors