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
jseow
Frequent Visitor

How to get dynamic count with date cutoff?

Hi all,

 

I have attached a sample data set for the problem I'm working on . I have a simple products and reviews table which are joined on product id. 

 

I am trying to create a view with time(month) on the x-axis that over time shows me in a combo chart:

1. (Line) The percentage of products that existed by the end of the given month that had at least 1 review.

2. (Column)The # of products that had at least 1 review by the end of the given month.

3. (Column)The # of products that had at least 10 reviews by the end of the given month.

 

I think I did #1 and 2 correctly, by creating 2 new measures and am stuck on # 3, trying to build off of what I did for #2, but the changes I've tried are not producing the desire results:

Products 1+ Reviews =
CALCULATE(
DISTINCTCOUNT(Reviews[Product ID]),

FILTER(ALL(Reviews),Reviews[Review Status] = "Published" && Reviews[Review Date] <=MAX(Reviews[Review Date]))
)

 

I assume I need a measure that filters to reviews based on the date, then groups by product ID, then filter off anything less than 10 total? Or maybe using the SUMMARIZE function? Any help would be appreciated.

 

Here is my most recent attempt:

 

Products 10+ Reviews = 
CALCULATE(
	DISTINCTCOUNT(Reviews[Product ID]),
	FILTER(
		SUMMARIZE (
			Reviews,
			Reviews[Product ID],
			"review_count", 
			CALCULATE(
				COUNTROWS(Reviews),
				FILTER(
					Reviews,
					Reviews[Review Status] = "Displaying" && Reviews[Review Date]<=MAX (Reviews[Review Date])
				)
			)
		),
		review_count >= 10
	)
)

 

But I get an error "Failed to resolve name 'review_count'. It is not a valid table, cariable, or function name."

I thought I declared the review_count table in the Summarize function, so how do I use it to Filter?

 

Thanks!

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @jseow,

 

 

I have checked the .pbix file you uploaded, you should wrap the 'review_count' with square brackets [].

 

Products 10+ Reviews = 
CALCULATE(
	DISTINCTCOUNT(Reviews[Product ID]),
	FILTER(
		SUMMARIZE (
			Reviews,
			Reviews[Product ID],
			"review_count", 
			CALCULATE(
				COUNTROWS(Reviews),
				FILTER(
					Reviews,
					Reviews[Review Status] = "Displaying" && Reviews[Review Date]<=MAX (Reviews[Review Date])
				)
			)
		),
		[review_count] >= 10
	)
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yulgu-msft

 

Thanks for the reply! It looks like using [review_count] allows the measure to evaluate, so the syntax is fixed. Unfortunately, it looks like my logic is off somewhere else, as when I add this measure to my chart, it does not show any columns (presumably it evaluates to 0 for all months?)

 

Based on the sample data, there should be a product that gets to 10 displayed reviews in May, then a second product in October, so I am not sure what part of my measure is logically incorrect.

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.