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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Mirithu
Helper II
Helper II

Of CALCULATE and filters

Hello,

I have two tables - Country and Language - as follows: 

tables.png

The relationship is as below on Country[CountryID] and Language[CID]

 

relatonship.png

I would like to list the number of countries for each language .

 

I have a simple measure of the count of countries as follows: 

CountryCnt = COUNT( Country[CountryID] )

 

But if I add it to a table, this is the result. It shows the same value across all languages:
wrong.png
The desired result I want is this one:

 

wanted.png

 

I can use CALCULATE as follows to get the correct value for each language, but then I have to specify the language in the filter:

 

CountryCnt English =
    CALCULATE (
    [CountryCnt],
    FILTER (
        'Language',
        'Language'[Lang] = "English"
    )
)
 
But how do I get the desired result for all languages as indicated?
1 ACCEPTED SOLUTION
Hariharan_R
Solution Sage
Solution Sage

Hi @Mirithu 

Try the below measure.

 

Measure =
VAR _X =
SUMMARIZE (
Languages,
Languages[Language],
"Count", CALCULATE ( COUNT ( Country[Country] ) )
)
RETURN
SUMX ( _x, [Count] )

 

Thanks

Hari

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

You can create a measure like

Num countries per language =
CALCULATE (
    COUNTROWS ( Country ),
    CROSSFILTER ( Country[Country ID], Language[CID], BOTH )
)
HotChilli
Super User
Super User

You would not use the Country table at all to get the desired result.

Pull Language from the Language table on to a visual.  Then drag CID on to the visual and change the aggregation to COUNT

Hariharan_R
Solution Sage
Solution Sage

Hi @Mirithu 

Try the below measure.

 

Measure =
VAR _X =
SUMMARIZE (
Languages,
Languages[Language],
"Count", CALCULATE ( COUNT ( Country[Country] ) )
)
RETURN
SUMX ( _x, [Count] )

 

Thanks

Hari

Thank you @Hariharan_R . The measure works perfectly.

If you do not mind I would like to probe futher into it.

 

I noticed that you used SUMMARIZE in the variable. If I take the SUMMARIZE only and put in a table, I get the correct result.
But if I use SUMMARIZECOLUMNS as below, the result is wrong - same number for all rows. Even if I remove the CALCULATE, the result is still wrong.

 

SUMMARIZECOLUMNS(
    'Language'[Language],
    "Count", CALCULATE( COUNT( Country[Country] ) )
    )


Does SUMMARIZECOLUMNS ignore the current filter like CALCULATE does? 
And how would you get the correct result using SUMMARIZECOLUMNS?

 

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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