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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
char23
Helper I
Helper I

How to count rows of filtered table based on slicer selection

I have the following table below. The months are ordered according to the [Date Rank] column with 1 being the most current month. I have a 1 measure that selects the previous month. So if March is selected, the measure is 3. If Apr is selected, the measure is 2. How can I make a measure to count the number of items/rows in the previous month and place in a card visual. So if Apr is selected as the current month, I want to count the number of rows where Date Rank = 2. And the answer would be 5 since there are 5 rows for march. I also have the following code below, but it looks like my current CALCULATE(COUNTROWS statement does not work because every time I select a month with a filter, the car visual just shows blank. It works when I pass the function a number, but not with the variable. Thank you for any help on solving this. 

 

IDStatusDate RankMonth
ANot Late3Jan
BNot Late3Jan
CFinished3Jan
DNot Late3Jan
ANot Late2March
BRe-opened2March
CLate2March
DLate2March
ELate2March
ALate1Apr
BLate1Apr
CLate1Apr

 

Slicer I have to select month:

 

char23_0-1722527221791.png

 

First measure I have to select the date rank of the previous month:

 

Daterankofpreviousmonth =
VAR currentselecteddaterank = SELECTEDVALUE('Table'[Date Rank])
RETURN
IF(
    ISBLANK(currentselecteddaterank),
    BLANK(),
    currentselecteddaterank + 1
)
 
 
My current measure to count the number of rows where Table[Date Rank] = daterankofpreviousmonth. But this does not work. The card visual just shows blank. 
 
Countprevious =

VAR currentselecteddaterank = [Daterankofpreviousmonth]
RETURN
IF(
    ISBLANK(currentselecteddaterank),
    BLANK(),
    CALCULATE(
        COUNTROWS('Table'),
        'Table'[Date Rank] = currentselecteddaterank
 )
)
3 REPLIES 3
v-kaiyue-msft
Community Support
Community Support

Hi @char23 ,

 

You can modify your MEASURE.

Countprevious = 
VAR previousdaterank = [Daterankofpreviousmonth]
RETURN
IF(
    ISBLANK(previousdaterank),
    BLANK(),
    CALCULATE(
        COUNTROWS('Table'),
        ALL('Table'), // Ensure the filter context is removed
        'Table'[Date Rank] = previousdaterank
    )
)

vkaiyuemsft_0-1722561961996.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This works when looking to count a single value. But when I add it to a visual that has grouping from another column, it shows the same number for each group. 

Hi @char23 ,

 

Sorry, could you please describe the problem you are experiencing in more detail and visually with a screenshot or in some other way? This will help us to better assist you in solving the problem.

 

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.