cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
jschlereth Member
Member

Count based on Min / Max Date by Quarter

So I have two measures that calculate the min and max date by quarter. These measures reside within what's basically a calendar table. When I add the quarter field, I can add the min / max dates to the table visualization without any issues. But now I'm trying to create another measure that counts the number of records based on that min and max date within that quarter. 

 

I've tried numerous things, but most recently: 

CALCULATE(Count(Salesforce[Id]), FILTER(CalendarTable,CalendarTable[FILE_DATE] = [MinFileDate]))

 

To no avail. I realize this probably has to do with some row-level context, but I can't seem to figure out the solution. The result right now is a count of all IDS by the entire Quarter (the first column in the table), but it's ignoring the MinFileDate filter. I think that's because at the row level all dates are the MinFileDate, but I need to "break out" of that to be MinFileDate by the Quarter itself. 

 

I need the Count of all IDs by Quarter AND on the minimum file date. 

 

Any help/thoughts would be appreciated. Thanks.

 

Jonathan 

1 ACCEPTED SOLUTION

Accepted Solutions
jschlereth Member
Member

Re: Count based on Min / Max Date by Quarter

@v-shex-msft@dkay84_PowerBI,

 

Thanks for both of your responses. I ended up going a different route. @v-shex-msft, I could never get your example to work properly. 

 

I ended up making a secondary table that only included the max and min dates (SQL Query). I then used the LOOKUPVALUE function to pull that min/max date respectively in my overall table. I then compared the file date in that table to the min/max date and used "yes" or "no" if it matched that date (as another column in the raw data file).

 

I then more simply created a calculation (measure) that filtered in those that were "yes". 

 

I appreciate your assistance in responding. 

 

Jonathan 

View solution in original post

3 REPLIES 3
Microsoft dkay84_PowerBI
Microsoft

Re: Count based on Min / Max Date by Quarter

Please provide some sample data
Community Support Team
Community Support Team

Re: Count based on Min / Max Date by Quarter

Hi @jschlereth,


I'd like to suggest you use maxx or minx function to get the minfiledate/maxfiledate per quarter.

 

Sample:

 

Count of MinFileDate= 
var minDate= MINX(FILTER(ALL(Salesforce),[Date].[QuarterNo]=MAX([Date].[QuarterNo])&&[Date].[Year]=MAX([Date].[Year])),[Date])
return
CALCULATE(Count(Salesforce[Id]), FILTER(CalendarTable,CalendarTable[FILE_DATE] = minDate))


Count of MaxFileDate= 
var MaxDate= MAXX(FILTER(ALL(Salesforce),[Date].[QuarterNo]=MAX([Date].[QuarterNo])&&[Date].[Year]=MAX([Date].[Year])),[Date])
return
CALCULATE(Count(Salesforce[Id]), FILTER(CalendarTable,CalendarTable[FILE_DATE] = MaxDate))

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI
jschlereth Member
Member

Re: Count based on Min / Max Date by Quarter

@v-shex-msft@dkay84_PowerBI,

 

Thanks for both of your responses. I ended up going a different route. @v-shex-msft, I could never get your example to work properly. 

 

I ended up making a secondary table that only included the max and min dates (SQL Query). I then used the LOOKUPVALUE function to pull that min/max date respectively in my overall table. I then compared the file date in that table to the min/max date and used "yes" or "no" if it matched that date (as another column in the raw data file).

 

I then more simply created a calculation (measure) that filtered in those that were "yes". 

 

I appreciate your assistance in responding. 

 

Jonathan 

View solution in original post

Helpful resources

Announcements
Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors