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
atziovara
Helper I
Helper I

Weighted Average formula issue

  • I want to compute the Weighted Average for the following set of data:

 

Table Name: TableBI

WaveCompany IDWeightsQuestionsAnswersWeighted AnswersPeriods
110,006Demand change compared to the previous 6 months-1-0,0062022 H2
110,006Expected change in demand in the next 6 months10,0062023 H1
110,006Liquidity problems intensity10,0062022 H2
110,006Expected change in employment002023 H1
120,001Demand change compared to the previous 6 months10,0012022 H2
120,001Expected change in demand in the next 6 months10,0012023 H1
120,001Liquidity problems intensity-1-0,0012022 H2
120,001Expected change in employment10,0012023 H1
130,0057Demand change compared to the previous 6 months10,00572022 H2
130,0057Expected change in demand in the next 6 months002023 H1
130,0057Liquidity problems intensity002022 H2
130,0057Expected change in employment002023 H1
210,006Demand change compared to the previous 6 months10,0062023 H1
210,006Expected change in demand in the next 6 months002023 H2
210,006Liquidity problems intensity002023 H1
210,006Expected change in employment002023 H2
220,001Demand change compared to the previous 6 months10,0012023 H1
220,001Expected change in demand in the next 6 months10,0012023 H2
220,001Liquidity problems intensity-1-0,0012023 H1
220,001Expected change in employment10,0012023 H2
230,0057Demand change compared to the previous 6 months10,00572023 H1
230,0057Expected change in demand in the next 6 months002023 H2
230,0057Liquidity problems intensity-1-0,00572023 H1
230,0057Expected change in employment10,00572023 H2

*Weighted Answers is calculated as: Weights * Answers

**In the column "Answers" -1 denotes decrease (or zero problems for Liquidity problems intensity), 0 denotes stability (or low to medium intensity problems), and 1 denotes increase (or high intensity problems).

 

  • I created the following measure:
Weighted Average =
VAR SelectedChar = SELECTEDVALUE(TableBI[Questions])
VAR SelectedPrice = SELECTEDVALUE(TableBI[Answers])
VAR Numerator =
SUMX(
FILTER(
'TableBI',
NOT(ISBLANK('TableBI'[Weighted Answers])) &&
NOT(ISBLANK('TableBI'[Weights])) &&
'TableBI'[Questions] = SelectedChar &&
'TableBI'[Answers] = SelectedPrice
),
IF(
'TableBI'[Answers] = -1,
('TableBI'[Weighted Answers] * (-1)),
IF(
'TableBI'[Answers] = 0,
'TableBI'[Weights],
'TableBI'[Weighted Answers]
)
)
)
VAR Denominator =
SUMX(
FILTER(
'TableBI',
NOT(ISBLANK('TableBI'[Weighted Answers])) &&
NOT(ISBLANK('TableBI'[Weights])) &&
'TableBI'[Questions] = SelectedChar
),
'TableBI'[Weights]
)
RETURN
DIVIDE(Numerator, Denominator)

 

  • More specifically, when Answer = -1 I want the first SUMX to be calculated for each row of Weighted Answers myltiplied by -1 (for which the filters are true of course), when Answer = 0 I want the first SUMX to be calculated for each row of Weights, and when Answer = 1, I want the first SUMX to be computed for each row of Weighted Answers
  • The problem that I am encountering is that I only receive 1 as an answer for all Waves whether I select 0, 1, or -1 as an Answer on my slicer. It seems that for some reason the Numerator and the Denominator are the same, so one of the filters is not being applied.

 

4 REPLIES 4
123abc
Community Champion
Community Champion

Here's a modified version of your DAX measure:

 

Weighted Average =
VAR SelectedChar = SELECTEDVALUE(TableBI[Questions])
VAR SelectedPrice = SELECTEDVALUE(TableBI[Answers])

VAR Numerator =
SUMX(
FILTER(
TableBI,
NOT(ISBLANK(TableBI[Weighted Answers])) &&
NOT(ISBLANK(TableBI[Weights])) &&
TableBI[Questions] = SelectedChar &&
TableBI[Answers] = SelectedPrice
),
IF(
SelectedPrice = -1,
TableBI[Weighted Answers] * -1,
IF(
SelectedPrice = 0,
TableBI[Weights],
TableBI[Weighted Answers]
)
)
)

VAR Denominator =
SUMX(
FILTER(
TableBI,
NOT(ISBLANK(TableBI[Weighted Answers])) &&
NOT(ISBLANK(TableBI[Weights])) &&
TableBI[Questions] = SelectedChar
),
TableBI[Weights]
)

RETURN
DIVIDE(Numerator, Denominator)

@123abc 
Thank you for your answer!


I am afraid the modified version that you sent me is still not working. I am now receiving 1 for all waves when Answer = 0 or 1, and -1 when Answer = -1.


It seems like the rows of the Numerator are not filtered correctly, and the Numerator is the same as the Denominator.

hi @atziovara ,

 

not sure if i fully get you, try like:

1) feed the slicers with isolated calculated tables like:

answers = VALUES(TableBI[Answers])
questions = VALUES(TableBI[Questions])


2) plot a visual table with a slightly modified measure based on yours like:

Weighted Average = 
VAR SelectedChar = SELECTEDVALUE(Questions[Questions])
VAR SelectedPrice = SELECTEDVALUE(Answers[Answers])
VAR Numerator =
SUMX(
    FILTER(
        'TableBI',
        NOT(ISBLANK('TableBI'[Weighted Answers])) 
            &&NOT(ISBLANK('TableBI'[Weights])) 
            &&'TableBI'[Questions] = SelectedChar 
            &&'TableBI'[Answers] = SelectedPrice
    ),
    IF(
        'TableBI'[Answers] = -1,
        ('TableBI'[Weighted Answers] * (-1)),
        IF(
            'TableBI'[Answers] = 0,
            'TableBI'[Weights],
            'TableBI'[Weighted Answers]
        )
    )
)
VAR Denominator =
SUMX(
    FILTER(
        'TableBI',
        NOT(ISBLANK('TableBI'[Weighted Answers])) 
            &&NOT(ISBLANK('TableBI'[Weights])) 
            &&'TableBI'[Questions] = SelectedChar
    ),
    'TableBI'[Weights]
)
RETURN DIVIDE(Numerator, Denominator)


it worked like:

FreemanZ_0-1701268154985.png

 

@FreemanZ 
Thank you very much for your response! 

This partially resolves the issue! However, I have two more questions related to your answer:

 

(1) Some of the Answers of the original data do not have -1, 0, or 1 as values. They can take values varying from -100 to 100. Therefore, when I select a specific question in the relevant slicer of tables Question, the slicer with the Answers showcases all possible values and not the ones that are associated with the question I selected. 

Please note that it would not be preferable to just filter the Answers slicer, in case in the future the Weighted Average is expanded with more IF statements. I would like to be able to see the Answers that relate to the specific Question that is selected.

Is there a way to fix this?

 

(2) Also, if I want to compare all 3 of the Answers to a Question in one graph, would I need to make 2 more disconnected tables with 2 new measures (which will have the same formula as [Weighted Average] though), plus 2 more disconnected tables which will have Questions as their only column, and 2 more disconnected tables which will have Answers as their column?

Thank you very much in advance!

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.