Forum Discussion

Asfaa5's avatar
Asfaa5
Frequent Visitor
6 years ago
Solved

Active Contracts Count by Year/Month

Hello Team,

 

im new to Power Bi. I need a help on Dax Measure calculation of Active Contracts Count by Year/Month.

 

I have a Table "Sales" with 7,65,000 data. Sales Table contains "Policy Number", "Contract Start Date", "Contract End Date".

 

Need output as below :

 

YearMonthActive Count
2019Jan4000
 Feb4500
 Mar5000
 Apr5500
 May6000
 Jun6500
 Jul7000
 Aug7500
 Sep8000
 Oct8500
 Nov9000
 Dec9500
2020Jan9800
 Feb10100
 Mar10000
 Apr11000
 May12000
 Jun11500
 Jul10000
 Aug9000
 Sep7500
 Oct7000
 Nov6500
 Dec6000
2021Jan5500
 Feb5000
 Mar4500
 Apr4000
 May3500
 Jun3000
 Jul2500
 Aug2000
 Sep1500
 Oct1000
 Nov100
 Dec10

 

Can anyone help me on this.

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi Asfaa5 

    Create one date table.

     

    Date=Calender(DATE (2010, 1, 1), DATE (2020, 12, 31)).

    Then create year and month column in the date table.

     

    Then create measure suggested by Anonymous .

     

    And add year, month and measure to your table visual.

     

    Thanks & regards,
    Pravin Wattamwar
    www.linkedin.com/in/pravin-p-wattamwar

    If I resolve your problem Mark it as a solution and give kudos.

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    What is the required logic for active contracts?

     

    Is it where end date in blank() or 12/31/9999?

     

    New measure=Calculate(Count[Table[Contract]),Filter(table,Table[end_Date]='12/31/9999')

     

    Please modify filter condition as per your active contracts logic.

     

    Thanks & regards,
    Pravin Wattamwar
    www.linkedin.com/in/pravin-p-wattamwar

    If I resolve your problem Mark it as a solution and give kudos.

    • Asfaa5's avatar
      Asfaa5
      Frequent Visitor

      Hi. Thanks for your revert.

       

      Logic is for Showing How many Contract are going to be active in Jan-20, Feb-20, Mar-20, like this till Contract Expire completely.

       

      There is no blank in Contract End Date. Last date is till 31/12/2027.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Usually in cases like this the best is to create a separate date table contaning all dates covering the time period you want to analyze. The table should not be connected to the data table with any relations.

     

    Then you create a measure something like this:

     

     

    Active Contracts = CALCULATE(
      COUNTROWS('Sales'),
      FILTER('Sales', 'Sales'[Contract Start Date] <= MAX('Dates'[Date]) && 'Sales'[Contract End Date] >= MIN('Dates'[Date]))
    )

     

     

    I have assumed each row has one contract, so COUNTROWS('Sales') is the number of contracts.

    Finally, use year / month / date from the dates table in combination with the new measure.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Asfaa5 

      Create one date table.

       

      Date=Calender(DATE (2010, 1, 1), DATE (2020, 12, 31)).

      Then create year and month column in the date table.

       

      Then create measure suggested by Anonymous .

       

      And add year, month and measure to your table visual.

       

      Thanks & regards,
      Pravin Wattamwar
      www.linkedin.com/in/pravin-p-wattamwar

      If I resolve your problem Mark it as a solution and give kudos.