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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
TCavins
Helper V
Helper V

Count Rows where field exists in another filtered table

I have an SP in SQL that uses date parameters not to filter the data but to assign values in a case statement. I'm trying to move this into Power BI but I'm struggling with the parameter.

 

What I'm trying now is I have a date table with a slicer assigned to it. My main dataset (Query1 for this example) is not linked to the date table. I have a few case statements where I want to get counts from Query1:

 

1. Query1.Date <= filtered start date AND (Query1.xxx ISBLANK() OR Query1.yyy <= 'SOME DATE')

 

2. Query1.Date exists in the filtered date table between the slicer dates

 

3. Similar to option 2 with an AND clause checking Query1.SomeField is in ('xxx','yyy','zzz')

 

Is this possible? What's the best solution? I don't want to filter the results but assign specific values based on the filtered date table/slicer. 

1 ACCEPTED SOLUTION

Think I figured it out.

 

Measure = CALCULATE(COUNTROWS(Query2), FILTER(Query2, Query2[Date_Placed] >= MIN('Dates'[Date]) && Query2[Date_Placed] <= MAX('Dates'[Date])))

So if I adjust the slicer on the date field, the measure automatically updates. 

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@TCavins Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Think I figured it out.

 

Measure = CALCULATE(COUNTROWS(Query2), FILTER(Query2, Query2[Date_Placed] >= MIN('Dates'[Date]) && Query2[Date_Placed] <= MAX('Dates'[Date])))

So if I adjust the slicer on the date field, the measure automatically updates. 

My current Stored Procedure has @BeginDate and @EndDate as parameters. These do not filter the results but are used in a CASE statement to get a count.

 

CASE WHEN Date1 <= @StartDate AND (column1 is null OR column2 <= '1/1/2021') THEN 1 END as MyField1

WHEN Date1 BETWEEN @StartDate and @ENDDate THEN 1 END As MyField2

WHEN Date2 BETWEEN @StartDate and @EndDate AND (Column3 IN ('xxx','yyy')) THEN 1 END as MyField3

 

I don't want the end user having to modify parameters when viewing the App in the Power BI Service. So I thought I'd create a Date table with just a date column and apply a slicer to it. Then I would be able to create measures to determine the case statement above and use the slicer/date table instead of parameters to see if Date1 falls within the filtered/sliced table.

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors