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
MYDATASTORY
Resolver I
Resolver I

Dax NOT IN | How to calculate lost and gained

Hi

 

I would like advice on how to calculate lost and gained players. much appreciated in advance 

Data Modelling

  • Contract Status.[Contract Status id]
  • Player.[Player Id]

Business rules 

Each Player can have many contracts  which can be on different status i.e expired and pending renew 

Each player can have   more than one contract on different  contract status

Requirement:

Count  Lost Players,

we use the filter  on Contract Start Date and Contract End Date 

we only count these players their contract status = Expired, Canceled  and Not Active(Status id (3,4&5))

we want to exclude  any contract on contract status: Active & Pending approval (status id (1&2))

-----------------------------

Count gained Players

we use the filter  on Contract Start Date to calculate new players based on the Contract Start Date slicer 

we only count these players their contract status =Active & Pending approval (status id (1&2))

 

Players Contract Table

Player IdContract IDContract Start DateContract End Date Contract StatusContract Status id
Player A10001/01/19801/2/19981Expired 3
Player A10101/01/19801/2/19981Expired 3
Player A10201/01/19801/2/19981Expired 3
Player A10301/01/19801/2/19981Expired 3
Player A10401/01/19801/2/19981Expired 3
Player A10501/01/19801/2/19981Expired 3
Player A10607/01/202001/02/2023Active1
Player B10708/01/202004/04/2018Expired 3
Player B10809/01/202004/04/2018Expired 3
Player B10910/01/202004/04/2018Expired 3
Player B11011/01/202004/04/2018Expired 3
Player B11112/01/202004/04/2018Expired 3
Player B11213/01/202004/04/2018Expired 3
Player B11314/01/202004/04/2018Expired 3
Player B11415/01/202004/04/2018Expired 3
Player C11516/01/199920/02/1999Expired 3
Player C11616/01/199920/02/1999Expired 3
Player C11716/01/199920/02/1999Canceled5
Player C11816/01/199920/02/1999Canceled5
Player C11916/01/199920/02/1999Expired 3
Player C12016/01/199920/02/1999Expired 3
Player C12116/01/199920/02/1999Expired 3
Player C12216/01/199920/02/1999Not Active4
Player C12316/01/199920/02/2020Pending Approval2
Player C12416/01/199920/02/2022Active1
Player C12516/01/199920/02/2022Active1

 

Players Names 

Player NamePlayer ID
Player ANameA
Player BNameB
Player CNameC

 

Contract Status

 

Contract StatusContract Status id
Expired 3
Active1
Pending Approval2
Not Active4
Canceled 5
2 REPLIES 2
v-lili6-msft
Community Support
Community Support

hi  @MYDATASTORY 

Could you please tell me if your problem has been solved?

If it is, could you please mark the helpful replies as Answered?

if not please share your expected output based on the sample data.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
FrankAT
Community Champion
Community Champion

Hi @MYDATASTORY 

if I understood you right you can do it like this. See also attached pbix file:

 

30-09-_2020_22-23-48.png

Count Lost Players = 
VAR _Calculation = 
    CALCULATE(
        [Count Players],
        FILTER(
            'Players Contract Table',
            'Players Contract Table'[Contract Status id] IN {3, 4, 5}
        )
    )
RETURN
    IF(_Calculation = BLANK(), "No Lost Player", _Calculation & " Lost Player(s)"
)

Count Gained Players = 
VAR _Calculation = 
    CALCULATE(
        [Count Players],
        FILTER(
            'Players Contract Table',
            'Players Contract Table'[Contract Status id] IN {1, 2}
        )
    )
RETURN
    IF(_Calculation = BLANK(), "No Gained Player", _Calculation & " Gained Player(s)"
)

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

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.