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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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!

1 ACCEPTED SOLUTION
Icey
Community Support
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]
    )

m.PNG

 

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]
)

t.PNGc.PNG

 

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.

View solution in original post

2 REPLIES 2
Icey
Community Support
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]
    )

m.PNG

 

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]
)

t.PNGc.PNG

 

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
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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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