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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
WishAskedSooner
Continued Contributor
Continued Contributor

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
Super User
Super User

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



Did I answer your question?
If so, mark my post as a solution!
Also consider helping someone else in the forums!

Proud to be a Super User!


LinkedIn

View solution in original post

3 REPLIES 3
Nasif_Azam
Super User
Super User

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



Did I answer your question?
If so, mark my post as a solution!
Also consider helping someone else in the forums!

Proud to be a Super User!


LinkedIn

@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. 😊



Did I answer your question?
If so, mark my post as a solution!
Also consider helping someone else in the forums!

Proud to be a Super User!


LinkedIn

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.