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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
MYDATASTORY
Resolver I
Resolver I

How to calculate and count not into a field

Hi Please advise on how to count lost and gained players using not in. 

Each player can have many contracts (ContractReference)

Each player contracts be on different stages depending on which sports they play.

Below is the player contract status

ContractStatusid              ContractStatus

1                                              Expired

2                                              Cancelled

3                                              Active

4                                              PendingDecesion

5                                              Approvalpending

Below is the dummy data with two players id, but with difference contract references

PlayerID    ContractReference        ContractStatusid  ContractStatusContract Start DateContractEnd Date 

PlayerIDContractReferenceContractStatusidContractStatusContract Start DateContractEnd Date 
100DummyDataRef11Expired 01/01/198001/08/2020
100DummyDataRef22Cancelled02/01/198001/07/2020
100DummyDataRef31Expired 03/01/198003/05/2020
100DummyDataRef42Cancelled04/01/198003/04/2020
100DummyDataRef51Expired 05/01/198003/05/2020
100DummyDataRef62Cancelled06/01/198003/06/2020
100DummyDataRef71Expired 07/01/198003/08/2020
100DummyDataRef82Cancelled08/01/198003/09/2020
100DummyDataRef91Expired 09/01/198003/09/2020
100DummyDataRef102Cancelled10/01/198003/09/2020
200DummyDataRef121Expired 01/01/198001/08/1920
200DummyDataRef132Cancelled02/01/198001/09/1920
200DummyDataRef143Active03/01/198003/01/2023
200DummyDataRef154PendingDecesion04/01/198003/01/2023
200DummyDataRef165Approvalpending05/01/198003/01/2023
200DummyDataRef171Expired 06/01/198003/01/2000
200DummyDataRef182Cancelled07/01/198003/01/2000
200DummyDataRef193Active08/01/198003/01/2023
200DummyDataRef204PendingDecesion09/01/198003/01/2023
200DummyDataRef215Approvalpending 10/01/198003/01/2023

Requirements/help request

Question 1: Count number of players lost

Logic: count these players with ContractStatusid is in 1 and 2 and ContractStatusidNOT IN <>’3,4,5’

We also use the Contract start date and end date as a filter to lost players on a particular month/year

Question 2: Count the number of players gained.

Logic: count these players with ContractStatusid is in ‘3,4,5’ and ContractStatusid NOT IN <>’1,2’ 

We use the contract start date to filter the number of players gained on a particular month/year

Answer

  • Number of Gained players 1 Playerid   200
  • Number of Lost players      1 playerid   100
2 REPLIES 2
FrankAT
Community Champion
Community Champion

Hi @MYDATASTORY 

with your sample data and logic - if I understood you well - I get the following solution. It's different to yours answer:

 

21-09-_2020_15-44-51.png

 

Count number of players gained = 
CALCULATE(COUNTROWS('Table'),'Table'[ContractStatusid] IN {3,4,5})

Count number of players lost = 
CALCULATE(COUNTROWS('Table'),'Table'[ContractStatusid] IN {1,2})

 

Take a look at the attached pbix file.

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

@FrankAT  Thanks for your help.

Below is the answer I was expecting 

1 Player lost

Player id 100 because their status is in in 1,2 and not in 3,4,5

----------

1 Player gained 

Player id 200 because their status is in in 3,4,5 and not in 1,2

basically they must not appear on the other contract status because one player can lose one contract but still have another one active contract and that why we need on in ( select count playerid from player where contractstatusid NOT in(select contractstatusid where contractstatusid not in (3,4,5)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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