Forum Discussion

jk_adelaide's avatar
jk_adelaide
Frequent Visitor
2 years ago
Solved

open Claims monthly count

Hi,

I want to count the open claims from the below table. Any claims not closed will carry to the next month as open.

i used the below measure but not giving accurate data.

Total open Claims = CALCULATE(COUNT('Claims'[Claims ID]),FILTER('Claims','Claims'[Created]<=ENDOFMONTH('Date'[Date]) && 'Claims'[Closed]>=ENDOFMONTH('Date'[Date])))
i have created a inactive relationship with date table with Claims Created and Closed.
Claims IDCreatedClosed
190926094828/09/202217/05/2023
190927150017/10/202228/03/2023
190928104527/10/202228/03/2023
190929133903/11/202228/03/2023
190908110813/12/202203/02/2023
190908132321/12/202217/02/2023
190908112322/02/202330/05/2023
190810121830/03/202303/04/2023
190811081714/04/202319/05/2023
190811085215/05/202319/05/2023
190812100715/05/202312/07/2023
190817102105/06/202315/06/2023
191708122305/06/202315/06/2023
190817181106/06/202315/06/2023
190923181212/06/202315/06/2023
190928163912/06/202328/06/2023
190926114616/08/2023 

 

if you do a manual calculations it will be like below but measure gives different.  Thanks in advance.

Month Yearmanualmeasure
Jan-2366
Feb-2374
Mar-2362
Apr-2342
May-2351
Jun-2361
Jul-231no value
Aug-231no value
  • 1) create calendar table

    Calendar = VAR BaseCalendar =
        CALENDAR ( DATE ( 2022, 1, 1 ), DATE (2023, 12, 31 )) 
      
    RETURN
        GENERATE (
            BaseCalendar,
            VAR BaseDate = [Date]
            VAR YearDate = YEAR ( BaseDate )
            VAR MonthNumber = MONTH ( BaseDate )
            VAR YearMonthNumber = YearDate * 12 + MonthNumber - 1
            RETURN ROW (
                "Year", YearDate,
                "Month Number", MonthNumber,
                "Month", FORMAT ( BaseDate, "mmmm"),
                "Year Month Number", YearMonthNumber,
                "Year Month", FORMAT ( BaseDate, "mmm yy")
            )
        )

    2) measure

    count the open claims = 
    VAR _GenaretDateBetWeen = 
           GENERATE (
                    'Claims',
                    DATESBETWEEN (
                        'Calendar'[Date],
                        'Claims'[Created],
                        IF ( ISBLANK ( 'Claims'[Closed] ), 'Claims'[Created], 'Claims'[Closed] )
                    ))
    
    VAR _SelectColumns_And_Distinct = 
     DISTINCT(SELECTCOLUMNS(_GenaretDateBetWeen,
                    "Claims ID",[Claims ID] ,
                    "@Month_Year",FORMAT ([Date], "mmm yy")))
    VAR _SelectOnlydateCoumns=   
                  SELECTCOLUMNS(_SelectColumns_And_Distinct,"@Month_Year",[@Month_Year])
    
    VAR _INTERSECT =
             INTERSECT(_SelectOnlydateCoumns,VALUES('Calendar'[Year Month]))
    
    RETURN  
    COUNTROWS(_INTERSECT)

     

     

     

5 Replies

  • 1) create calendar table

    Calendar = VAR BaseCalendar =
        CALENDAR ( DATE ( 2022, 1, 1 ), DATE (2023, 12, 31 )) 
      
    RETURN
        GENERATE (
            BaseCalendar,
            VAR BaseDate = [Date]
            VAR YearDate = YEAR ( BaseDate )
            VAR MonthNumber = MONTH ( BaseDate )
            VAR YearMonthNumber = YearDate * 12 + MonthNumber - 1
            RETURN ROW (
                "Year", YearDate,
                "Month Number", MonthNumber,
                "Month", FORMAT ( BaseDate, "mmmm"),
                "Year Month Number", YearMonthNumber,
                "Year Month", FORMAT ( BaseDate, "mmm yy")
            )
        )

    2) measure

    count the open claims = 
    VAR _GenaretDateBetWeen = 
           GENERATE (
                    'Claims',
                    DATESBETWEEN (
                        'Calendar'[Date],
                        'Claims'[Created],
                        IF ( ISBLANK ( 'Claims'[Closed] ), 'Claims'[Created], 'Claims'[Closed] )
                    ))
    
    VAR _SelectColumns_And_Distinct = 
     DISTINCT(SELECTCOLUMNS(_GenaretDateBetWeen,
                    "Claims ID",[Claims ID] ,
                    "@Month_Year",FORMAT ([Date], "mmm yy")))
    VAR _SelectOnlydateCoumns=   
                  SELECTCOLUMNS(_SelectColumns_And_Distinct,"@Month_Year",[@Month_Year])
    
    VAR _INTERSECT =
             INTERSECT(_SelectOnlydateCoumns,VALUES('Calendar'[Year Month]))
    
    RETURN  
    COUNTROWS(_INTERSECT)

     

     

     

    • jk_adelaide's avatar
      jk_adelaide
      Frequent Visitor

      Hi Ahmedx,

      thanks but i can't open this with my version of power bi.