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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
WestWinter
Helper II
Helper II

Weighted Average

DateRegionCountryMales
01/01/2021AmericaUS100
01/01/2021AmericaCanada150
01/01/2021AmericaMexico110
01/01/2021AsiaChina160
01/01/2021AsiaJapan100

So above, America will have 360 males while Asia have 260

 

DateCountryMetricValue
01/01/2021USRisk of Cancer0.05
01/01/2021MexicoRisk of Cancer0.02
01/01/2021CanadaRisk of Cancer0.024
01/01/2021ChinaRisk of Cancer0.053
01/01/2021JapanRisk of Cancer0.02

 

So I am trying to find the weighted average of the above Metric (which could have many forms since it is in a long format)

 

I just want to match country by country, where the metric is multipled by the no of males in the first table accordingly to the dates.

2 ACCEPTED SOLUTIONS
CNENFRNL
Community Champion
Community Champion

Merge table in PQ

PQ.png

 

Or DAX measures,

Ratio = 
IF (
    ISINSCOPE ( 'CASES'[Country] ),
    CALCULATE (
        AVERAGE ( LOOKUP[Value] ),
        TREATAS (
            SUMMARIZE ( 'CASES', 'CASES'[Date], LOOKUP[Country] ),
            LOOKUP[Date],
            LOOKUP[Country]
        )
    )
)
Total Weighted = 
SUMX (
    DISTINCT ( 'CASES'[Country] ),
    CALCULATE ( MAX ( 'CASES'[Males] ) ) * [Ratio]
)

Screenshot 2021-08-22 114801.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

v-luwang-msft
Community Support
Community Support

Hi @WestWinter ,

Try like below ,create two column:

Column = 
VAR lookupvalue1 =
    LOOKUPVALUE (
        'Table B'[Value],
        'Table B'[Date], TableA[Date],
        'Table B'[Country], TableA[Country],
        0
    )
RETURN
    lookupvalue1 * TableA[Males]
Weighted Average = 
SUMX (
        FILTER ( TableA, TableA[Region] = EARLIER ( TableA[Region] ) ),
        TableA[Column]
    )
        / CALCULATE (
            COUNT ( 'TableA'[Country] ),
            FILTER ( TableA, TableA[Region] = EARLIER ( TableA[Region] ) )
        )

Final get :

vluwangmsft_0-1629875874907.png

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

 

Best Regards

Lucien

View solution in original post

3 REPLIES 3
v-luwang-msft
Community Support
Community Support

Hi @WestWinter ,

Try like below ,create two column:

Column = 
VAR lookupvalue1 =
    LOOKUPVALUE (
        'Table B'[Value],
        'Table B'[Date], TableA[Date],
        'Table B'[Country], TableA[Country],
        0
    )
RETURN
    lookupvalue1 * TableA[Males]
Weighted Average = 
SUMX (
        FILTER ( TableA, TableA[Region] = EARLIER ( TableA[Region] ) ),
        TableA[Column]
    )
        / CALCULATE (
            COUNT ( 'TableA'[Country] ),
            FILTER ( TableA, TableA[Region] = EARLIER ( TableA[Region] ) )
        )

Final get :

vluwangmsft_0-1629875874907.png

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

 

Best Regards

Lucien

CNENFRNL
Community Champion
Community Champion

Merge table in PQ

PQ.png

 

Or DAX measures,

Ratio = 
IF (
    ISINSCOPE ( 'CASES'[Country] ),
    CALCULATE (
        AVERAGE ( LOOKUP[Value] ),
        TREATAS (
            SUMMARIZE ( 'CASES', 'CASES'[Date], LOOKUP[Country] ),
            LOOKUP[Date],
            LOOKUP[Country]
        )
    )
)
Total Weighted = 
SUMX (
    DISTINCT ( 'CASES'[Country] ),
    CALCULATE ( MAX ( 'CASES'[Males] ) ) * [Ratio]
)

Screenshot 2021-08-22 114801.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

TomMartens
Super User
Super User

Hey @WestWinter ,

 

you can use the DAX function LOOKUPVALUE (https://dax.guide/lookupvalue/) to pull the number of males to the second table by creating a calculated column in table 2.

 

Hopefully, this provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.