Forum Discussion

NewPBIe's avatar
NewPBIe
Icon for Helper II rankHelper II
3 years ago
Solved

New, active and closed Contracts

Hello everybody. I've got a Date Table (Calender) and a Table with IDs, Start date and End date for some Contracts (Data).

 

I need to answer three different questions pro each Period (fiscal year october - september):

1. how many new contracts  (in this period)

2. how many active contracts (from this and the previus periods)

3. how many closed contracts (in this period)

 

Now 1 and 3 are easy: I connected Calender[Date] with both [Start Date] and [End Date] from Data and selected the correct relastionship between the Tables. 

 

I am stuck with 2, since I can' t ignore the active relationship and every measure keeps counting the new contracts and not the active ones. 

 

Sample Data / Input:

 

IDSTARTEND
A16.10.202030.08.2021
B16.10.202031.01.2021
C21.12.202031.04.2021
D13.01.2021 
E08.03.202130.06.2021
F01.09.202130.09.2021

 

 

Output:

 New ClosedActivewhich IDs should be counted in active
Okt. 20202A;B
Nov. 20002A;B
Dez. 20103A;B;C
Jan. 21114A;B;C;D
Feb. 21003A;C;D
Mrz. 21104A;C;D;E
Apr. 21014A;C;D;E
Mai. 21003A;D;E
Jun. 21013A;D;E
Jul. 21002A;D
Aug. 21012A;D
Sep. 21112D;F

 

What am I doing wrong? Thank you in advance!

  • Try

    Active contracts =
    VAR ReferenceDate =
        MAX ( 'Calendar'[Date] )
    VAR Result =
        CALCULATE (
            COUNTROWS ( 'Table' ),
            REMOVEFILTERS ( 'Date' ),
            'Table'[Start date] <= ReferenceDate
                && (
                    ISBLANK ( 'Table'[End date] )
                        || 'Table'[End date] > ReferenceDate
                )
        )
    RETURN
        Result
    

1 Reply

  • Try

    Active contracts =
    VAR ReferenceDate =
        MAX ( 'Calendar'[Date] )
    VAR Result =
        CALCULATE (
            COUNTROWS ( 'Table' ),
            REMOVEFILTERS ( 'Date' ),
            'Table'[Start date] <= ReferenceDate
                && (
                    ISBLANK ( 'Table'[End date] )
                        || 'Table'[End date] > ReferenceDate
                )
        )
    RETURN
        Result