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

The Fabric community is upgrading! Read all of the details including the timeline and what you can expect. Learn more

Reply
Yussufff23
Frequent Visitor

Help convert Excel formula to use in Power Query

For forum.png

Hello everyone, I ask you to help convert the formula from excel to power guerry language m or language power bi. In the table associated with diseases, according to the criteria from column D to column D:J . I use this formula to create auto-calculated map legends with cities and countries. My formula looks like this: 

 

 

=IF(K2=0,"no information",
IF(AND(MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2)<=K2,K2<ROUND(INT(AVERAGE(MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2),AVERAGE(MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2),MAXIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2)))),1-LEN(INT(AVERAGE(MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2),AVERAGE(MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2),MAXIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2))))))),
ROUND(INT(MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2)),1-LEN(INT(MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2))))&"-"&ROUND(INT(AVERAGE(MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F: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J2),MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2)),MAXIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2)))))<=K2,">"&ROUND(INT(AVERAGE(AVERAGE(MAXIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2),MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2)),MAXIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2))),1-LEN(INT(AVERAGE(AVERAGE(MAXIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2),MINIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2)),MAXIFS(K:K,$C:$C,C2,$D:$D,D2,$E:$E,E2,$F:$F,F2,$H:$H,H2,$I:$I,I2,$J:$J,J2))))),"Error")))))

 

 

 

My function divides the column into several virtual areas according to the criteria, looks for the highs and lows and then finds the average between them, then writes the gap that includes the values.

 

Table:

https://docs.google.com/spreadsheets/d/1zwLm8m_Nc8JLcQkAsomnnZM_Aj_e8g62UK3ladgBloc/edit#gid=2047737...

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Yussufff23 ,

 

For the MINIFS and MAXIFS functions, please kindly refer to
Power Query Classic COUNTIFS | SUMIFS | AVERAGEIFS | MAXIFS | MINIFS Calculations [Simply Amazing]

 

Or you can use the Group By tool to find the max and min dates, then merge those dates back to the original data. See the Query sheet in the attached file.

 

Best Regards,

Stephen Tao

 

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

3 REPLIES 3
BA_Pete
Super User
Super User

Hi @Yussufff23 ,

 

The Power Query functions/statements you need are as follows:

 

IF(X, Y, IF(A, B, C)) = if X then Y else if A then B else C

AND(X, Y) = X and Y

ROUND(X) / INT(X) = Number.Round(X) (use different arguments to adjust output)

AVERAGE(X) = List.Average(X)

MIN(X) = List.Min(X)

MAX(X) = List.Max(X)

LEN(X) = Text.Length(X)

Convert text (X) > Number = Number.From(X)

Convert number (X) > Text = Text.From(X)

 

Best of luck 👍

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




In my formula, I used MINIF  and MAXIF functions

 

Anonymous
Not applicable

Hi @Yussufff23 ,

 

For the MINIFS and MAXIFS functions, please kindly refer to
Power Query Classic COUNTIFS | SUMIFS | AVERAGEIFS | MAXIFS | MINIFS Calculations [Simply Amazing]

 

Or you can use the Group By tool to find the max and min dates, then merge those dates back to the original data. See the Query sheet in the attached file.

 

Best Regards,

Stephen Tao

 

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

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.

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.