Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Check If Event Happened In Given Month

I have a table of events with start and end dates based on company:

EventIDCustomerIDStartDateEndDateStatus
1112/20/192/12/20Bad
213/12/203/29/20Bad
323/1/203/4/20Good
421/4/201/29/20Bad
532/6/202/21/20Good
632/24/203/3/20Bad

 

I then have a table that's connected by customer and month, and I want to create a calculated column (call it BadStatus below) to show EACH month where they had at least one actively "Bad" status. The results given the data above should look like this:

 

CustomerMonthBadStatus
11/1/20Bad
12/1/20Bad
13/1/20Bad
21/1/20Bad
22/1/20 
23/1/20 
31/1/20 
32/1/20Bad
33/1/20Bad

 

Let me know if you need any other info for guidance. Thanks!

  • Hi Anonymous ,

     

    Please check:

     

    You can create a measure like so:

    Measure BadStatus = 
    VAR t =
        CROSSJOIN (
            SUMMARIZE (
                Events,
                Events[CustomerID],
                Events[StartDate],
                Events[EndDate],
                Events[Status]
            ),
            SUMMARIZE ( Customers, Customers[Month] )
        )
    VAR t2 =
        FILTER (
            t,
            [Month]
                >= EOMONTH ( Events[StartDate], -1 ) + 1
                && [Month]
                    <= EOMONTH ( Events[EndDate], -1 ) + 1
                && [Status] = "Bad"
        )
    RETURN
        MAXX (
            FILTER (
                t2,
                [CustomerID] = MAX ( Customers[Customer] )
                    && [Month] = MAX ( Customers[Month] )
            ),
            [Status]
        )
    
    

     

    Or, create calculated column based on a calculated table like so:

    Table =
    VAR t =
        CROSSJOIN (
            SUMMARIZE (
                Events,
                Events[CustomerID],
                Events[StartDate],
                Events[EndDate],
                Events[Status]
            ),
            SUMMARIZE ( Customers, Customers[Month] )
        )
    VAR t2 =
        FILTER (
            t,
            [Month]
                >= EOMONTH ( Events[StartDate], -1 ) + 1
                && [Month]
                    <= EOMONTH ( Events[EndDate], -1 ) + 1
                && [Status] = "Bad"
        )
    RETURN
        SUMMARIZE ( t2, [CustomerID], [Month], [Status] )
    
    BadStatus = 
    LOOKUPVALUE (
        'Table'[Status],
        'Table'[CustomerID], Customers[Customer],
        'Table'[Month], Customers[Month]
    )
    

     

    BTW, .pbix file attached.

     

     

    Best Regards,

    Icey

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • Icey's avatar
    Icey
    Community Support

    Hi Anonymous ,

     

    Please check:

     

    You can create a measure like so:

    Measure BadStatus = 
    VAR t =
        CROSSJOIN (
            SUMMARIZE (
                Events,
                Events[CustomerID],
                Events[StartDate],
                Events[EndDate],
                Events[Status]
            ),
            SUMMARIZE ( Customers, Customers[Month] )
        )
    VAR t2 =
        FILTER (
            t,
            [Month]
                >= EOMONTH ( Events[StartDate], -1 ) + 1
                && [Month]
                    <= EOMONTH ( Events[EndDate], -1 ) + 1
                && [Status] = "Bad"
        )
    RETURN
        MAXX (
            FILTER (
                t2,
                [CustomerID] = MAX ( Customers[Customer] )
                    && [Month] = MAX ( Customers[Month] )
            ),
            [Status]
        )
    
    

     

    Or, create calculated column based on a calculated table like so:

    Table =
    VAR t =
        CROSSJOIN (
            SUMMARIZE (
                Events,
                Events[CustomerID],
                Events[StartDate],
                Events[EndDate],
                Events[Status]
            ),
            SUMMARIZE ( Customers, Customers[Month] )
        )
    VAR t2 =
        FILTER (
            t,
            [Month]
                >= EOMONTH ( Events[StartDate], -1 ) + 1
                && [Month]
                    <= EOMONTH ( Events[EndDate], -1 ) + 1
                && [Status] = "Bad"
        )
    RETURN
        SUMMARIZE ( t2, [CustomerID], [Month], [Status] )
    
    BadStatus = 
    LOOKUPVALUE (
        'Table'[Status],
        'Table'[CustomerID], Customers[Customer],
        'Table'[Month], Customers[Month]
    )
    

     

    BTW, .pbix file attached.

     

     

    Best Regards,

    Icey

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks, Icey! Had to throw a NOT(ISBLANK()) condition for the Status as some Statuses were blank in my dataset but everything else worked great. Appreciate the help.