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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Salman_usman
Frequent Visitor

Calculate sum of weights for distinct ResponseIDs

Hi,

 

I have a calculated data table (combined questions table). It has the following columns: Response ID, Question Number, Response Option, Question Option, Country Weight.

 

I am trying to calculate 'the sum of Country Weight for distinct Response IDs per question number'. Now this should be a measure. For example, say for Question Number 5, a total of 20 respondents have responded. This means there are a total of 20 distinct response IDs (the table might show the count as much more due to unpivoting but the distinct count is 20). For these 20 distinct response IDs, I would like to see the sum of Country Weights.

 

Now there are a couple of other tables in the data model: such as a demographics table that has country, age, income, etc. data. The calculation should be filterable by all these using slicers (the combined questions table is connected with the demographics table and things work fine in that area). Wanted to mention this so that we can take this into account while building the calculation.

 

Thank you in advance for your help.

Rough sketch of what I am trying to achieve is below:

Salman_usman_0-1592864085806.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Salman_usman ,

Then you can create a calculated table with below formula:

Table 2 = 
SUMMARIZECOLUMNS ( 'Questionnaire'[Question No.],
'Questionnaire'[Response ID],
"DistinctCW",MAX('Questionnaire'[Country Weight]) )

summarize table.JPG

Best Regards

Rena

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @Salman_usman ,

You can create a measure as below to get it:

Sum of distinct = 
VAR _tab =
    SUMMARIZECOLUMNS (
        'Questionnaire'[Question No.],
        'Questionnaire'[Response ID],
        "DistinctCW", MAX ( 'Questionnaire'[Country Weight] )
    )
RETURN
    SUMX ( _tab, [DistinctCW] )

sum of distinct.JPG

Best Regards

Rena

Hi @Anonymous , I received the below error message after adding your formula:

 

MdxScript(Model) (50,1) Calculation error in measure 'Combined Questions'[Measure]: SummarizeColumns() and AddMissingItems() may not be used in this context.

 

Not sure what's wrong 😞

Anonymous
Not applicable

Hi @Salman_usman ,

Then you can create a calculated table with below formula:

Table 2 = 
SUMMARIZECOLUMNS ( 'Questionnaire'[Question No.],
'Questionnaire'[Response ID],
"DistinctCW",MAX('Questionnaire'[Country Weight]) )

summarize table.JPG

Best Regards

Rena

Perfect, this did the trick. One more thing, I need to have two columns in this table instead of 1. So both Country Weight and Global Weight. How do I tweak the formula for this please?

amitchandak
Super User
Super User

@Salman_usman , Try like

sumx(values(Table[Country Weight]),[Country Weight])
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak Sorry some weird numbers coming 😞

 

We need distinct responseids and then a sum of the weights. Potentially, also include a filter in the calculation to point it to a particular question number and response type. 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors