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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
char23
Helper II
Helper II

Count rows based on slicer selection is showing blank

I am trying to write a measure. I have the following table. I want the user to be able to select a month. If the user selects June. Then I want previous month = 2 which is May. 1 plus the date rank gives the group of the previous month. Then I want the measure to count the number of rows where multiple filter conditions are met. I want to count rows where Dank rank =2, Status and Previous Status = "Not Normal" and where Type = "Task". So this would return a 1 because there is only one row where all conditions are met. But I want the measure to update based on what the user selects as the current month. If the user does not select a month, then I want to show blank for the measure.

 

IDStatusDate RankPrevious StatusMonthType
ANormal3No previousMarTask
BNormal3No previousMarTask
CNot Normal3No previousMarTask
DNot Normal3No PreviousMarNot Task
ANot Normal2NormalMay Task
BNormal2NormalMay Not Task
CNormal2Not NormalMay Not Task
DNormal2Not NormalMay Task
ANot Normal1Not NormalJuneTask
BNot Normal1NormalJuneTask
DNormal1NormalJuneTask
ENormal1 JuneTask

 

This is the measure I have so far. But it doesnt work. I am not sure how to modify. I also want this to be able to work if the measure is placed on a bar visual that is grouped by another column on the x-axis. 

 

VAR SelectedMonthRank =
    CALCULATE(
        MAX('Table'[Date Rank]),
        FILTER(
            ALL('Table'),
            'Table'[Month] = SELECTEDVALUE('Table'[Month])
        )
    )
VAR PreviousMonthDateRank = SelectedMonthRank + 1
RETURN
IF(
    ISBLANK(SelectedMonthRank),
    BLANK(),
    CALCULATE(
        COUNTROWS('Table'),
        FILTER(
            'Table',
            'Table'[Date Rank] = PreviousMonthDateRank
        )
    )
)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @char23 ,

 

You can try to disconnect the relationship between Table1 and Table 2:

vcgaomsft_1-1724748826901.png

then use this measure:

MEASURE = 
VAR __selected_month_rank =
    SELECTEDVALUE ( 'Table2'[Date Rank] )
VAR __result =
    IF (
        ISBLANK ( __selected_month_rank ),
        BLANK (),
        IF ( 
            SELECTEDVALUE( 'Table1'[Date Rank] )
                IN { __selected_month_rank, __selected_month_rank + 1 },
            CALCULATE (
                COUNTROWS ( 'Table1' ),
                'Table1'[Status] = "Not Normal"
                    && 'Table1'[Previous Status] = "Not Normal"
                    && 'Table1'[Type] = "Task"
            )
        )
    )
RETURN
    __result

Output:

vcgaomsft_0-1724748806099.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

6 REPLIES 6
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the  below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_1-1723002284672.png

 

 

Jihwan_Kim_0-1723002256183.png

 

expected result measure: = 
VAR _SelectedYearMonthEndDate =
    SELECTEDVALUE ( 'Calendar'[Year-Month sort] )
VAR _PreviousYearMonthEndDate =
    EOMONTH ( _SelectedYearMonthEndDate, -1 )
VAR _t =
    CALCULATETABLE (
        Data,
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Year-Month sort] = _PreviousYearMonthEndDate
        ),
        'Status'[Status] = "Not Normal",
        'Type'[Type] = "Task"
    )
RETURN
    COUNTROWS ( _t )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you! This is not exactly how I have my table/file arranged, but this somewhat works for me (especially using the calculatetable function), but when I add the measure to a bar graph, it shows the same total for each group. Is there anyway I can fix this? 

Hi,

Thank you for your message.

Please share your sample pbix file's link and the expected outcome of how the barchart looks like (which columns are used for the bar chart axis, and how the result looks like).

Thank you.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Sorry, just realized that I left a column of data from this. 

char23_0-1723208246913.png

 

Want to compare the columns Status and Previous status. If the user selects Jun, I want to count rows where Dank rank =2, Status and Previous Status = "Not Normal" and where Type = "Task". So this would return a 1 because there is only one row where all conditions are met.

 

 

Anonymous
Not applicable

Hi @char23 ,

 

You can try to disconnect the relationship between Table1 and Table 2:

vcgaomsft_1-1724748826901.png

then use this measure:

MEASURE = 
VAR __selected_month_rank =
    SELECTEDVALUE ( 'Table2'[Date Rank] )
VAR __result =
    IF (
        ISBLANK ( __selected_month_rank ),
        BLANK (),
        IF ( 
            SELECTEDVALUE( 'Table1'[Date Rank] )
                IN { __selected_month_rank, __selected_month_rank + 1 },
            CALCULATE (
                COUNTROWS ( 'Table1' ),
                'Table1'[Status] = "Not Normal"
                    && 'Table1'[Previous Status] = "Not Normal"
                    && 'Table1'[Type] = "Task"
            )
        )
    )
RETURN
    __result

Output:

vcgaomsft_0-1724748806099.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hello, thank you very much for your help. I don't think I can upload, but I have included snippets of how my tables are in powerbi and an example of the clustered column visual I am trying to create with the measure. Also, if possible, whenever the user selects a current month to view, I want to automatically populate the second most current month (like in my visual, Jun is selected, so May data is also shown). Thank you again!

 

Table1

char23_0-1723165469423.png

Table2

char23_1-1723165494606.png

 

char23_2-1723165673206.png

The visual I want to create

char23_3-1723165734066.png

 

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.