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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Calculate Average Data based on Filters

Hi there,

I am trying to create two sets of data for comparison, one based on a single table the other based on values from two tables.
These tables are imported via SQL Database through power query. I have no direct access to modify / create tables in the SQL databases so hoping to do this in Power BI.

 

Table 1 - Predictions
Predicted condition over a range of years (full dataset has a range of 20 years)

predictions   
UIDXscenarioyrcondition
1|1020208.41
1|1020219.92
1|1020229.9
1|2020208.85
1|2020219.92
1|2020229.9
2|1020208.98
2|1020219.14
2|1020228.97
3|1020206.83
3|1020216.48
3|1020225.87
4|1020209.46
4|102021-0.47
4|102022-1.05
5|1020207.27
5|1020217.53
5|1020227.26
6|1020209.33
6|1020219.26
6|1020229.16
6|2020209.22
6|2020218.97
6|2020228.82

 

Table 2 - Area
Table that stores standardised area across the database.

area 
UIDXarea
1|11287
1|22485
2|11625.9
3|12448.6
4|13300
5|12492.9
6|15368
6|24048

The tables are in a relationship based on the UIDX field.


I would like to calculate the following:
Query 1 - Average 'condition' - result to be displayed in a card using the following criteria:

  • Where Scenario = 0
  • And yr = 2021

e.g. cond_avg = CALCULATE(AVERAGE(predictions[condition]),FILTER(predictions,predictions[yr] = "2021"))

I used a New Measure to try and calculate Query 1. It initially appeared fine but when I add the results to a card I get the following error, interestingly the columns are both format Decimal Number.:
Calculation error in measure 'predictions'[cond_avg]: DAX comparison operations do not support comparing values of type Number with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.


Query 2 - Average condition x Area - display average condition multiplied by area in a card based on the following criteria:

  • Where Scenario = 0
  • And yr = 2021

I have tried to get a result from joining tables thought have been unsuccessful. I am trying to replicate the following (assume the query 1 will need to be integrated?):
Sum(predictions[condition]*area[area])/sum(area[area])

 

Is anyone able to assist? Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @v-zhangti 

 

Thank you for your quick response.

Query 1 - results look as expected, terrific.

 

Query 2 - the core data is a much larger sample set but comparing your query against sample data there is a discrepency. The methodology you suggested looks sound though I think there may be a mismatch with UIDX so have forwarded off to my engineer for review.

Will update when I have a response from them.

Cheers

Matt_au

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @v-zhangti 

 

Thank you for your quick response.

Query 1 - results look as expected, terrific.

 

Query 2 - the core data is a much larger sample set but comparing your query against sample data there is a discrepency. The methodology you suggested looks sound though I think there may be a mismatch with UIDX so have forwarded off to my engineer for review.

Will update when I have a response from them.

Cheers

Matt_au

v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

For Query 1, you can try the following methods.

cond_avg =
CALCULATE (
    AVERAGE ( Predictions[condition] ),
    FILTER ( ALL ( Predictions ), [yr] = 2021 && [scenario] = 0 )
)

vzhangti_0-1641267584442.png

 

In response to Query 2, I don't know if I understand it correctly, please confirm if it is the result you expect.

Add calculated columns:

Area =
IF (
    [scenario] = 0
        && [yr] = 2021,
    LOOKUPVALUE ( Area[area], Area[UIDX], [UIDX] ),
    BLANK ()
)
Column = [condition]*[Area]

Measure:

Query 2 =
DIVIDE ( SUM ( Predictions[Column] ), SUM ( Area[area] ) )

vzhangti_1-1641267940874.png

If the method I provided above can't solve your problem, what's your expected result? Could you please provide more details for it?

 

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.

Anonymous
Not applicable

Thank you for your help @v-zhangti checked with our engineer and he was happy with the results.

 

Cheers

Matt_au

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors