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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pureswing
Frequent Visitor

help with two formulas from EXCEL to use in queries

Hello guys, here again looking for help. I've been using for months two excel formulas without problems. Now I want to go one step ahead and use it directly in power query but I'm still a novice in M lenguage, the folrmulas in cuestion are :

=IF(A2<>A1,B2,C1 & " / " & B2)

and: 

=IF(A2<>A3,CONCATENATE(C2),"")

And example of the result of using both formula:

OrderDesign=IF(A2<>A1,B2,C1 & " / " & B2)=IF(A2<>A3,CONCATENATE(C2),"")
5666MAR-324MAR-324MAR-324
6987EVE-001EVE-001 
6987EVE-012EVE-001 / EVE-002EVE-001 / EVE-002
8012LAT-101LAT-101 
8012EVE-001LAT-101 / EVE-001 
8012LIN-005LAT-101 / EVE-001 / LIN-005LAT-101 EVE-001 / LIN-005
9823MAR-310MAR-310MAR-310

the final step would be a filter row on column D to eliminate blanks rows.... I appreciate any help please Smiley Happy

By the way, sorry if this might be a dumb question but I wonder if there is any web or blog with information on how to "convert" excell formulas to M language using real escenarios ??(for dummies xd). It happens that I don't have time to read for 3 hours everytime I am stuck with a formula so it wold be great to find some information similar to this: 

FuntionExcelPower QueryResult
IF ExampleExample Obtaining the same result


Regards, Liu

1 ACCEPTED SOLUTION

Just group by order, defining some dummy operation (e.g. Max) for Design, and then adjust the code to have the ext combined.

 

As follows:

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Order", Int64.Type}, {"Design", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Order"}, {{"Result", each Text.Combine([Design], " / "), type text}})
in
    #"Grouped Rows"
Specializing in Power Query Formula Language (M)

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

Looks like you are doing things with previous rows and/or next rows in a table. I suppose that might be possible in M language but I have never personally tried that other than perhaps referencing the table twice with an Index and doing a join perhaps. Perhaps @MarcelBeug or @ImkeF can help with that.

 

In general, an IF statement in M code looks like this:

 

= if [Column] < 2 then 1 else 2

I think what you would have to do in M code would be to grab the next 2 rows by doing a filter into a temp table essentially (a query step that sits outside of the main flow). I'll try to come up with an example. Then, in theory you could use it somehow. I'm not really sure how that would all work though, you'd have to write a function and do some looping. Nasty. I think I would just import the table 3 times with an Index column that started at 2 for the first time, 1 for the second one and 0 for the third one. Then you could join all three tables on these Index columns and effectively have all three rows in the same row. Something like that.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi smoupre, well @MarcelBeug help me a couple days ago with this post, and his solution was a bless, I spend a whole week looking for a solution and he did it in just minutes. Sadly there is no option for donations in the forum otherwise I would gladly give a contribution for your time and help guys:) 

In the beginning I was okay using two tables (one using the formulas and another one with the result) but the data its getting bigger and I have some performance issues, so I am trying to get the same result with just one table and I think (maybe I'm wrong) the performance could improve .

Take a look at this thread:

 

https://community.powerbi.com/t5/Desktop/Calculating-Price-change-and-Growth/m-p/329158#M147023

 

It has some things in there working with EARLIER that might help you as this is a way to work with other rows in DAX (not Power Query). May or may not be a fit. The MAXX, SUMX and MINX functions essentially do table scans so for large data sets they can be slow.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Just group by order, defining some dummy operation (e.g. Max) for Design, and then adjust the code to have the ext combined.

 

As follows:

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Order", Int64.Type}, {"Design", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Order"}, {{"Result", each Text.Combine([Design], " / "), type text}})
in
    #"Grouped Rows"
Specializing in Power Query Formula Language (M)

Amazing it works!!!,  thanks guys @Greg_Deckler @MarcelBeug Smiley Very Happy

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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