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

Two filters for the same column

 
  • I want to compute the Weighted Average for one of the following Questions, based on the value of the Answer to another Question. For example, I would like to compute the Weighted Average of the Liquidity Problems Intensity for companies who expect that their Demand in the next 6 months will increase (Question= "Expected change in demand in the next 6 months", Answer = 1). My dataset is like this:

 

Table Name: TableBI

WaveCompany IndexCompany IDWeightsQuestionsAnswersWeighted AnswersPeriods
111-10,006Demand change compared to the previous 6 months-1-0,0062022 H2
111-10,006Expected change in demand in the next 6 months10,0062023 H1
111-10,006Liquidity problems intensity10,0062022 H2
111-10,006Expected change in employment002023 H1
121-20,001Demand change compared to the previous 6 months10,0012022 H2
121-20,001Expected change in demand in the next 6 months10,0012023 H1
121-20,001Liquidity problems intensity-1-0,0012022 H2
121-20,001Expected change in employment10,0012023 H1
131-30,0057Demand change compared to the previous 6 months10,00572022 H2
131-30,0057Expected change in demand in the next 6 months002023 H1
131-30,0057Liquidity problems intensity002022 H2
131-30,0057Expected change in employment002023 H1
212-10,006Demand change compared to the previous 6 months10,0062023 H1
212-10,006Expected change in demand in the next 6 months002023 H2
212-10,006Liquidity problems intensity002023 H1
212-10,006Expected change in employment002023 H2
222-20,001Demand change compared to the previous 6 months10,0012023 H1
222-20,001Expected change in demand in the next 6 months10,0012023 H2
222-20,001Liquidity problems intensity-1-0,0012023 H1
222-20,001Expected change in employment10,0012023 H2
232-30,0057Demand change compared to the previous 6 months10,00572023 H1
232-30,0057Expected change in demand in the next 6 months002023 H2
232-30,0057Liquidity problems intensity-1-0,00572023 H1
232-30,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 a disconnected table "Selected Characteristics" as:

 

SelectedCharacteristics =
SUMMARIZE'TableBI',
    'TableBI'[Questions],
   'TableBI'[Answers])

 

  • I created the following measure:

 

Weighted Average =
VAR SelectedQuestion1 = SELECTEDVALUE('TableBI'[Questions])
VAR SelectedQuestion2 = SELECTEDVALUE('SelectedCharacteristics'[Questions])
VAR SelectedPrice = SELECTEDVALUE('SelectedCharacteristics'[Answers])
RETURN
DIVIDE(
    SUMX(
        FILTER(
            'TableBI',
            NOT(ISBLANK('TableBI'[Weighted Answers])) &&
            NOT(ISBLANK('TableBI'[Weights])) &&
            'TableBI'[Questions] = SelectedQuestion1 &&
           CALCULATE(
               VALUES('TableBI'[Answers]), 'TableBI'[Questions] = SelectedCharacteristic2'TableBI'[Τιμή] = SelectedPriceALLEXCEPT('TableBI''TableBI'[Company Index])
           )
        ), 'Table'[Weighted Answers]
    ),
    SUMX(
        FILTER(
            'TableBI',
            NOT(ISBLANK('TableBI'[Weighted Answers])) &&
            NOT(ISBLANK('TableBI'[Weights])) &&
            'TableBI'[Questions] = SelectedCharacteristic1 &&
            CALCULATE(
               VALUES('TableBI'[Answers]), 'TableBI'[Questions] = SelectedCharacteristic2'TableBI'[Answers] = SelectedPriceALLEXCEPT('TableBI''TableBI'[Company Index])
           )
        ),
        'TableBI'[Weights]
    )
)

 

 

  • I added two slicers: one with Questions from TableBI and one with Questions and Answers from SelectedCharacteristics.
  • I added a Clustered Column Chart that has Waves on its X-Axis and Weighted Average on its Y-Axis
  • The problem that I am encountering is that this formula is only working when selected Answer = 1 or Answer = -1, however, when Answer = 0 I get back no values at all on the graph.
6 REPLIES 6
lbendlin
Super User
Super User

Since you are multiplying by zero that is the correct result of the calculation.  What would be your expected outcome?  What if you shifted your values by 2?  1 becomes 3, 0 becomes 2, -1 becomes 1  ?

@lbendlin Thank you for your response!

 

I don't want the calculation to take place on the row of 'Table'[Weighted Answers] where 'Table'[Questions] =SelectedQuestion2. The row of 'Table'[Weighted Answers] which will be summed nees to be the same as the row where 'Table'[Questions] = SelectedCharacteristic1. Therefore, no multiplication by 0 should take place.

 

Examples:

(1) SelectedQuestion1 = "Liquidity problems intensity"

SelectedQuestion2 = "Expected change in demand in the next 6 months"

SelectedPrice = 1

The expected result should be: [0,006 + (-0,001) + (-0,001)] / (0,006 + 0,001 + 0,001) = 0,5

 

(2) SelectedQuestion1 = "Liquidity problems intensity"

SelectedQuestion2 = "Expected change in demand in the next 6 months"

SelectedPrice = 0

The expected result should be: [0 + 0 + (-0,0057)] / (0,0057 +0,006 + 0,0057) = -0,32759

Anonymous
Not applicable

Hi @atziovara ,

Thanks for reaching out to us with your problem. Base on your description, there is one table named "TableBI". And you execute the following steps:

1. Create another disconnected calculated table "SelectedCharacteristics"

2. Create three sliceres, the applied fields on the slicers are from the field [Questions] of table 'TableBI',   the field [Questions] of table "SelectedCharacteristics" and  the field [Answers] of table "SelectedCharacteristics"

3. Create a measure to get the value --Here I'm not clear about the calculation logic, could you please explain more details on it with the examples and screenshot? Thank you.

For example: 


(1) SelectedQuestion1 = "Liquidity problems intensity"

SelectedQuestion2 = "Expected change in demand in the next 6 months"

SelectedPrice = 1

The expected result should be: [0,006 + (-0,001) + (-0,001)] / (0,006 + 0,001 + 0,001) = 0,5


According to the sample data and slicers, it will return the below data.

vyiruanmsft_1-1701769977858.png

Why the expected result not be: [0+(-0,001)+(-0,0057)]/[0,006 + 0,001 +0,0057]?

Best Regards

Hello @Anonymous ! Thank you very much for your answer!

Let me analyse the example of the calculation I am trying to perform:

 

(1) SelectedQuestion1 = "Liquidity problems intensity"

SelectedQuestion2 = "Expected change in demand in the next 6 months"

SelectedPrice = 1

The expected result should be: [0,006 + (-0,001) + (-0,001)] / (0,006 + 0,001 + 0,001) = 0,5

 

I would like to compute the Weighted Average of Liquidity problems intensity for the companies who have asnwered that the Expected change in demand in the next 6 months will be 1

 

The Questions & Answers in RED are the ones who check the conditions of the filtering for each Company ID. They ensure that the weighted average of Liquidity problems intensity for each company and wave will be calculated for SelectedQuestion2 = "Expected change in demand in the next 6 months" & SelectedPrice = 1. 

 

The weighted average is calculated as the sum of the Weighted Answers of Liquidity problems intensity (yellow background) divided by the sum of the Weights of Liquidity problems intensity (green background). It is based on the typical mathematical formula:

Weighted Mean = Σ (wi * xi) / Σwi

 

Therefore, the expected result is: [0,006 + (-0,001) + (-0,001)] / (0,006 + 0,001 + 0,001) = 0,5

 

atziovara_0-1702302025689.png

 

 

(2) SelectedQuestion1 = "Liquidity problems intensity"

SelectedQuestion2 = "Expected change in demand in the next 6 months"

SelectedPrice = 0

 

The logic is the same as above. 

The expected result is: [0 + 0 + (-0,0057)] / (0,0057 +0,006 + 0,0057) = -0,32759

 

atziovara_1-1702302115620.png

 

I don't see a "SelectedPrice"  column in your sample data?

@lbendlin 
As mentioned on my original post - inside the measure Weighted Average:
VAR SelectedPrice = SELECTEDVALUE('SelectedCharacteristics'[Answers])

This means that SelectedPrice is a slicer that takes its values from the column [Answers] of table 'SelectedCharacteristics'.

 

SelectedCharacteristics is a disconnected table that has been created from summarizing the original table, 'TableBI':

SelectedCharacteristics =
SUMMARIZE'TableBI',
    'TableBI'[Questions],
   'TableBI'[Answers])

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.