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
esuing
Helper I
Helper I

Record count using calendar date table

Hello everyone. I've been struggling with this for a while and wondering if someone can help. I'm trying to create a table that will return a count of active producers each month based on two date fields: Prod First Ship Date and Prod Term Date.  Here's a look at a sample of the table:

 

2019-07-18 23_20_23-DEV - Member and Voter Counts - Power BI Desktop.png

 

I would like my final table to show active producers on the last day of each month. To be consider active, a producer would have [Prod First Pickup Date] <= #date# AND (Prod Term Date is Null or Prod Term Date > #date#)

 

I do have a calendar table joined to each of the date fields and they have all dates included in them. Ultimately, I'm looking for something like this:

 

2019-07-18 23_24_43-DEV - Member and Voter Counts - Power BI Desktop.png

 

I can show either Month or Last Day of Month. Don't really care about that. I was able to get the last day of the month using this formula:

 

Max First Ship Date = CALCULATE(max('Prod First Ship Date Calendar'[Prod First Ship Date]),CROSSFILTER(Producer[Prod First Ship Date],'Prod First Ship Date Calendar'[Prod First Ship Date],None))
 
But everything I've tried since then to get a count of the number of active producers has failed. The numbers I got in the table now came from this formula, but it's only checking against the First Pickup Date and doens't take Term Date into account at all:
 
Member Count C = CALCULATE(COUNTROWS(Producer),FILTER(ALL('Prod First Ship Date Calendar'),'Prod First Ship Date Calendar'[Prod First Ship Date]<=MAX('Prod First Ship Date Calendar'[Prod First Ship Date])))
 
Any help would be greatly appreciated! 
 
Thanks!
Eric
 

 

 

1 ACCEPTED SOLUTION
d_gosbell
Super User
Super User

If you want to do a "between" style of join like this you can't really use relationships (in fact they will cause issues). So you could either remove them entirely or use the CROSSFILTER() function to switch them off for this measure as I have done below. A pattern like the following should give you what you want

 

Active Producers =
CALCULATE (
    COUNTROWS (
        FILTER (
            Producer,
            Producer[Prod First Ship Date] <= MAX ( 'Prod First Ship Date Calendar'[Prod First Ship Date] )
                && (
                    ISBLANK ( Producer[Prod Term Date] )
                        || Producer[Prod Term Date] > MAX ( 'Prod First Ship Date Calendar'[Prod First Ship Date] )
                )
        )
    ),
    CROSSFILTER ( Producer[Prod First Ship Date], 'Prod First Ship Date Calendar'[Prod First Ship Date], NONE )
)

View solution in original post

2 REPLIES 2
d_gosbell
Super User
Super User

If you want to do a "between" style of join like this you can't really use relationships (in fact they will cause issues). So you could either remove them entirely or use the CROSSFILTER() function to switch them off for this measure as I have done below. A pattern like the following should give you what you want

 

Active Producers =
CALCULATE (
    COUNTROWS (
        FILTER (
            Producer,
            Producer[Prod First Ship Date] <= MAX ( 'Prod First Ship Date Calendar'[Prod First Ship Date] )
                && (
                    ISBLANK ( Producer[Prod Term Date] )
                        || Producer[Prod Term Date] > MAX ( 'Prod First Ship Date Calendar'[Prod First Ship Date] )
                )
        )
    ),
    CROSSFILTER ( Producer[Prod First Ship Date], 'Prod First Ship Date Calendar'[Prod First Ship Date], NONE )
)

This worked great! As a beginner, I knew I need to use the CROSSFILTER function within my CALCULATE but didn't know where it made sense (inside the FILTER or not). 

 

Thanks!

Eric

 

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.