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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
WishAskedSooner
Responsive Resident
Responsive Resident

Generating a Lookup Table Help

HI Experts!

 

I am having difficulty generating a lookup table that I need for later processing in a measure. Here is a sample of my requirement and the problem.

 

I have the following table called 'Fact':

EIDAIDVAL1VAL2VAL3
130.10.050.025
140.20.10.05
150.30.150.075
230.40.20.1
240.50.250.125
250.60.30.15
330.70.350.175
340.80.40.2
350.90.450.225

 

Step 1: Calculate a needed temporary column

This involves adding the following column via the following DAX (for some reason the code format has disappeared from my editor, so I apologize for the poor formatting):

 

 
    VAR _NewVal =
        ADDCOLUMNS(
            'Fact',
            "NEWVAL",
            CALCULATE( SUM( 'Fact'[VAL1] ) )
            + CALCULATE( SUM( 'Fact'[VAL2]) ) * 0.1
            + CALCULATE( SUM( 'Fact'[VAL3] ) ) * 0.01
        )
 
which results in the following table:
EIDAIDVAL1VAL2VAL3NEWVAL
130.10.050.0250.10525
140.20.10.050.2105
150.30.150.0750.31575
230.40.20.10.421
240.50.250.1250.52625
250.60.30.150.6315
330.70.350.1750.73675
340.80.40.20.842
350.90.450.2250.94725

 

Step 2: Summarize by AID and calculate average NEWVAL for each AID

The final step is to generate the following lookup table which is the average of the above table by AID on NEWVAL:

 

Needed Table:

AIDAVG NEWVAL
30.421
40.52625
50.6315

 I have tried the following DAX but am getting the wrong values which is just the average of every NEWVAL:

 

    VAR _AvgNewVal =
        ADDCOLUMNS(
            SUMMARIZE(
                _NewVal,
                'Fact'[AID]
            ),
            "AVG NEW VAL",
                AVERAGEX( _NewVal, [NEWVAL] )
        )

 

Current Results (incorrect):

AIDAVG NEWVAL
30.52625
40.52625
50.52625

 

I am stuck and not sure what to do next. All your help is greatly appreciated!

1 ACCEPTED SOLUTION
Nasif_Azam
Impactful Individual
Impactful Individual

Hey @WishAskedSooner ,

It looks like the issue is coming from how the AVERAGEX function is being used. Try the DAX expression:

 

VAR _AvgNewVal =
    SUMMARIZE(
        'Fact',
        'Fact'[AID],
        "AVG NEW VAL", AVERAGEX(
            FILTER(
                _NewVal, 
                'Fact'[AID] = EARLIER('Fact'[AID])
            ),
            [NEWVAL]
        )
    )

 

If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


Best Regards,
Nasif Azam

View solution in original post

3 REPLIES 3
Nasif_Azam
Impactful Individual
Impactful Individual

Hey @WishAskedSooner ,

It looks like the issue is coming from how the AVERAGEX function is being used. Try the DAX expression:

 

VAR _AvgNewVal =
    SUMMARIZE(
        'Fact',
        'Fact'[AID],
        "AVG NEW VAL", AVERAGEX(
            FILTER(
                _NewVal, 
                'Fact'[AID] = EARLIER('Fact'[AID])
            ),
            [NEWVAL]
        )
    )

 

If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


Best Regards,
Nasif Azam

@Nasif_Azam,

 

That is some DAX Ninja! Thanks so much. Marking as a solution and much kudos!

Thank you so much for your kind words! I’m glad I could help. 😊

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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