March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello everyone,
I would like to add a condition to the existing M code.
Can you please help me?
I would also like to know if Buffer() is necessary for this code, knowing that I actually have about 2,000 rows on one side and 40 rows for the lookup table
I'm sorry for the picture but I don't know how to insert an Excel file
Thanks in advance
Regards
Solved! Go to Solution.
Hello - you could add the condition at the step in which you lookup the value from the other table, however, because you are returning more than one column that then needs to be expanded, doing so would present a complication since one condition would return a table and the other would return text. Instead, I recommend you add a conditional replacement after the expansion, like below. Based on your dataset size, I don't think it would be necessary to buffer.
SCRIPT
Table.ReplaceValue(#"Expanded Custom",each [Warehouse], each if [Catégorie] = "B" then "P" else [Warehouse],Replacer.ReplaceText,{"Warehouse"})
RESULT
Helle @Mahesh0016 ,
Thanks for your message,
I have just seen that it is possible to insert tables
Here is the data, I hope it will be used
Thank you in advance
Regards
let
Source = Excel.CurrentWorkbook(){[Name="Sales"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Catégorie", type text}, {"Product_ID", type text}, {"Sale", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", (x)=> Table.SelectRows(LookUp, (y)=> Text.Contains(x[Product_ID], y[ID]))),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Departement", "Warehouse"}, {"Departement", "Warehouse"})
in
#"Expanded Custom"
ID | Departement | Warehouse |
1 | ABC | L1 |
2 | DEF | L2 |
3 | GHI | L3 |
4 | JKL | L4 |
Catégorie | Product_ID | Sale |
A | V1 | 15 |
A | V2 | 38 |
B | V1 | 34 |
A | V3 | 15 |
A | V5 | 32 |
Hello - you could add the condition at the step in which you lookup the value from the other table, however, because you are returning more than one column that then needs to be expanded, doing so would present a complication since one condition would return a table and the other would return text. Instead, I recommend you add a conditional replacement after the expansion, like below. Based on your dataset size, I don't think it would be necessary to buffer.
SCRIPT
Table.ReplaceValue(#"Expanded Custom",each [Warehouse], each if [Catégorie] = "B" then "P" else [Warehouse],Replacer.ReplaceText,{"Warehouse"})
RESULT
Hello @jennratten ,
Thank you for your solution which works very well and the explanations
Otherwise, it's fast overall with 2,000 lines (about 5-6 seconds to refresh)
Have a nice day
Regards
You're welcome!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
21 | |
16 | |
13 | |
12 | |
9 |
User | Count |
---|---|
36 | |
31 | |
20 | |
19 | |
17 |