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

How can I write a COUNTROWS measure using value in a related table?

I have two tables. One table is my Calendar Table, the other table is my Data table, and they are both related by 1-* on a Date column. I need to create a dynamic count of rows in the Data table as long as the date on which that event occurred is marked as a "Work-Day" in the Calendar Table. I want to create a measure to accomplish this but cannot figure out how to do so without resorting to CALCULATE, which does not dynamically update when selections are made on the various visuals on the canvas.

 

With the data below, the count should be 1.

 

Calendar

Date              Category

1/1/2019           Off

1/2/2019           Off

1/3/2019       Work-Day

 

Data

Date                Event

1/1/2019        Holiday

1/2/2019        Holiday

1/3/2019       Conference

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create a measure

Workday Count = 
CALCULATE(     
    COUNTROWS( Data ),
   'Calendar'[Category] = "workday"
)

2.png

If it doesn't meet your needs, please tell me your expected result.

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create a measure

Workday Count = 
CALCULATE(     
    COUNTROWS( Data ),
   'Calendar'[Category] = "workday"
)

2.png

If it doesn't meet your needs, please tell me your expected result.

 

Best Regards
Maggie

 

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

jthomson
Solution Sage
Solution Sage

What are you doing to make it not "dynamically update"? I'd have thought either a calculate countrows of your data table where the related value is work-day ought to work, either that or just join in the category column into your data table in Power Query and then not use the calendar table at all?

parry2k
Super User
Super User

@Anonymous try this measure

 

Workday Count = 
CALCULATE(     
    COUNTROWS( Data ),
    'Calendar'[Category] = "Work-Day"
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.