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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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: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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)))))<=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

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

 

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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

Top Solution Authors
Top Kudoed Authors