cancel
Showing results for
Did you mean:
Highlighted
Helper II

## 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:

Any ideas?

thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User V

## Re: Measure for net gain/loss

Hi @rogerdea ,

You will need to unpivot the columns JoinDate and LeaveDate.

Click on Unpivot Columns

After unpivoting your table will look like below.

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

Regards,
Harsh Nathani

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

2 REPLIES 2
Highlighted
Responsive Resident

## Re: Measure for net gain/loss

Hi roger

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

Highlighted
Super User V

## Re: Measure for net gain/loss

Hi @rogerdea ,

You will need to unpivot the columns JoinDate and LeaveDate.

Click on Unpivot Columns

After unpivoting your table will look like below.

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

Regards,
Harsh Nathani

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

Announcements

#### Meet the 2020 Season 2 Power BI Super Users!

Find out who's part of the program this season, and welcome the new Super Users.

#### August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

#### July 2020 Community Highlights

Learn about the exciting things that happened in July.

#### Featured Data Story of The Month

All Data Stories Gallery contributions are reviewed for each month. We select a contribution and feature the community member the following month.

#### Power BI Dev Camp - Developing with .NET Core

Learn how to develop custom web applications for Power BI using .NET Core 3.1 and .NET 5.

Top Solution Authors
Top Kudoed Authors