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 September 15. Request your voucher.

Reply
djskro
Frequent Visitor

Erroneous Results from COUNTROWS() in Context-transition

Unless I'm missing something, I'm pretty sure this isn't supposed to happen:

 

 

EVALUATE
CALCULATETABLE (
    CALCULATETABLE (
        ADDCOLUMNS (
            VALUES ( Users[User ID] ),
            "Test Expression 1 - CORRECT",
                CALCULATE (
                    CONCATENATEX (
                        FILTER (
                            VALUES ( 'Privilege Conflicts'[Privilege 2 ID] ),
                            'Privilege Conflicts'[Privilege 2 ID]
                                IN VALUES ( Privileges[Privilege ID] )
                        ),
                        'Privilege Conflicts'[Privilege 2 ID],
                        " | "
                    )
                ),
            "Test Expression 2 - INCORRECT",
                CALCULATE (
                    COUNTROWS (
                        FILTER (
                            VALUES ( 'Privilege Conflicts'[Privilege 2 ID] ),
                            'Privilege Conflicts'[Privilege 2 ID]
                                IN VALUES ( Privileges[Privilege ID] )
                        )
                    )
                )
        ),
        CROSSFILTER ( 'Users and Privileges'[Privilege ID], Privileges[Privilege ID], BOTH )
    ),
    Users[User ID] IN { 102, 103 }
)

 

 

Results:

djskro_0-1739462008956.png

 

Notice how, for User ID = 102, the results in the test expressions are inconsistent, despite the fact that they are semantically basically the same.

 

For reference, note that the following produces expected results:

 

 

EVALUATE
CALCULATETABLE(
    CALCULATETABLE(
        {
            ( 
	            
	            -- Test Expression 1 - CORRECT
	            
	            CALCULATE(
	                CONCATENATEX(
	                    FILTER(
	                        VALUES( 'Privilege Conflicts'[Privilege 2 ID] ),
	                        'Privilege Conflicts'[Privilege 2 ID]
	                            IN VALUES( Privileges[Privilege ID] )
	                    ),
	                    'Privilege Conflicts'[Privilege 2 ID],
	                    " | "
	                ),
	                Users[User ID] = 102
	            ),
	            
	            -- Test Expression 2 - CORRECT (inconsistent with prior query)
	            
	            CALCULATE(
	                COUNTROWS(
	                    FILTER(
	                        VALUES( 'Privilege Conflicts'[Privilege 2 ID] ),
	                        'Privilege Conflicts'[Privilege 2 ID]
	                            IN VALUES( Privileges[Privilege ID] )
	                    )
	                ),
	                Users[User ID] = 102
	            ) 
            )
        },
        CROSSFILTER ( 'Users and Privileges'[Privilege ID], Privileges[Privilege ID], BOTH )
    ),
    Users[User ID] IN { 102, 103 }
)

 

 

Results:

djskro_1-1739463320187.png

 

---

 

It appears that something might not be functioning correctly between the context-transition and COUNTROWS(), but not fully sure.

 

@marcorusso @Jeffreywang 

 

---

 

Power BI version: 2.139.2054.0

 

Data model:

 

djskro_3-1739463602951.png

 

2 REPLIES 2
Anonymous
Not applicable

Hi, @djskro 

 

Can you provide example files and the output you expect? This will better help you solve the problem. Please remove any sensitive data in advance.

How to provide sample data in the Power BI Forum - Microsoft Fabric Community

 

Best Regards,

Community Support Team _Charlotte

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

Thank you for your reply.

 

I believe that this problem is evident from the information I've provided. In my first DAX statement, semantically speaking, "Test Expression 1" should not differ from "Test Expression 2" for User ID 102.

 

Would you not agree that, semantically, the results I've shown are problematic? If so, it seems that the appropriate next step would not be dependent on my particular PBIX file.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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