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 September 15. Request your voucher.

Reply
natabird3
Skilled Sharer
Skilled Sharer

convert excel formula to dax (averageifs)

Hello,

 

I am trying to convert the following sequence of calculation from an excel file to power bi, but am unable to do so with the last one avergeifs formula as it is not existing in power bi for some reason. So i have a column that i need to rank (values will vary per ID). I do that using new calculated column: 

Rank Value = RANK.EQ(Data[Value],Data[Value],DESC)
Afterwards I need to round the count of the numbers as it varies based on the ID (i need to get top 2% values, top 5%, top 10%, top 20%, top 25% and top 50% only for each ID). I believe i can do it like this for top 2%: 
top 2% = ROUND(COUNT(Data[Rank Value])*0.02,0)
And finally to get the desired result:3.JPG1.JPG2.JPGI need to do the averageifs but not sure how in power bi. Hope someone can help. Thanks in advance. 
 
 
 
 
2 ACCEPTED SOLUTIONS
v-lid-msft
Community Support
Community Support

Hi @natabird3 ,

 

First I create a calculate column to rank value, you can another rank function as well,

 

 

Rank = RANKX('Table2','Table2'[Value],,DESC)

 

 

convert-excel-formula-to-dax-averageifs-1.png

 

Then in another table, create a number column

 

 

Number = ROUND(COUNTROWS(Table2) * [TOP N],0)

 

 

convert-excel-formula-to-dax-averageifs-2.png

 

Then we can create a measure to calculate the result.

 

 

Result =
FORMAT (
    AVERAGEX (
        FILTER ( ALL ( Table2 ), [Rank] <= SELECTEDVALUE ( 'Calculate'[Number] ) ),
        [Value]
    ),
    "Percent"
)

 

convert-excel-formula-to-dax-averageifs-3.png

 

 

Or we can just use a calculate column to get same result

 

ResultColumn =
FORMAT (
    AVERAGEX ( FILTER ( Table2, [Rank] <= [Number] ), [Value] ),
    "Percent"
)

convert-excel-formula-to-dax-averageifs-4.png

 

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ DongLi
If this post helps, then please consider Accept it as the solution to help the other members find it more

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @natabird3 ,

 

The measure is dynamic but the calculated columns are computed during the database processing and then stored in the model. So In your scenario, we can only create a measure using following DAX to meet your requirement:

 

Result = 
VAR n =
    ROUND ( COUNTROWS ( 'Table' ) * SUM ( 'Calculate'[TOP N] ), 0 )
VAR t =
   ADDCOLUMNS ( 'Table', "rank", RANKX ( 'Table', [Value],, DESC ) )
RETURN
    FORMAT ( AVERAGEX ( FILTER ( t, [rank] <= n ), [Value] ), "Percent" )

convert-excel-formula-to-dax-averageifs-1.pngconvert-excel-formula-to-dax-averageifs-2.pngconvert-excel-formula-to-dax-averageifs-3.png

 

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ DongLi

If this post helps, then please consider Accept it as the solution to help the other members find it more

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-lid-msft
Community Support
Community Support

Hi @natabird3 ,

 

First I create a calculate column to rank value, you can another rank function as well,

 

 

Rank = RANKX('Table2','Table2'[Value],,DESC)

 

 

convert-excel-formula-to-dax-averageifs-1.png

 

Then in another table, create a number column

 

 

Number = ROUND(COUNTROWS(Table2) * [TOP N],0)

 

 

convert-excel-formula-to-dax-averageifs-2.png

 

Then we can create a measure to calculate the result.

 

 

Result =
FORMAT (
    AVERAGEX (
        FILTER ( ALL ( Table2 ), [Rank] <= SELECTEDVALUE ( 'Calculate'[Number] ) ),
        [Value]
    ),
    "Percent"
)

 

convert-excel-formula-to-dax-averageifs-3.png

 

 

Or we can just use a calculate column to get same result

 

ResultColumn =
FORMAT (
    AVERAGEX ( FILTER ( Table2, [Rank] <= [Number] ), [Value] ),
    "Percent"
)

convert-excel-formula-to-dax-averageifs-4.png

 

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ DongLi
If this post helps, then please consider Accept it as the solution to help the other members find it more

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello @v-lid-msft ,

Thank you for the proposed solution, i thought it works when i tried to implement it but now when i filter i am unable to get the desired result. I believe because of how we set the number formula, it counts the rows assuming each row is a different ID maybe, however we have some id's with multiple entries so if i filter per id i am not getting the desired result as nothing changes. For example, we can have the following situation, in this case i am getting the total for both ID's, anyway to only get per ID? Please let me know, thanks again for your help.

s.JPG

Hi @natabird3 ,

 

The measure is dynamic but the calculated columns are computed during the database processing and then stored in the model. So In your scenario, we can only create a measure using following DAX to meet your requirement:

 

Result = 
VAR n =
    ROUND ( COUNTROWS ( 'Table' ) * SUM ( 'Calculate'[TOP N] ), 0 )
VAR t =
   ADDCOLUMNS ( 'Table', "rank", RANKX ( 'Table', [Value],, DESC ) )
RETURN
    FORMAT ( AVERAGEX ( FILTER ( t, [rank] <= n ), [Value] ), "Percent" )

convert-excel-formula-to-dax-averageifs-1.pngconvert-excel-formula-to-dax-averageifs-2.pngconvert-excel-formula-to-dax-averageifs-3.png

 

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ DongLi

If this post helps, then please consider Accept it as the solution to help the other members find it more

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

It works perfect, thanks for the help.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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