SWITCH Function in Power Query

  Рет қаралды 38,359

Goodly

Goodly

Күн бұрын

Пікірлер: 116
@nonoobott8602
@nonoobott8602 Ай бұрын
You make M so easy to understand. The way you simplify and explain the concepts is just amazing. Thanks for sharing
@greisboy425
@greisboy425 9 ай бұрын
The if-else version is a lot easier, but I really love how you explain the other version, that's really help to make us understand m language more deeply. Awesome content.
@victor_wang_1
@victor_wang_1 9 ай бұрын
It's cool and clever, but I'd recommend sticking with the normal nested ifs as its more universally familiar. This technique, like much of custom M code, also breaks query folding which creates a different "scalability" problem if you have many records. As a final point (and this is only based on my experience), even ignoring query folding, it wouldn't surprise me if the nested ifs was more performant as I've found that iterating list access can have a noticeable impact. If you have many conditionals, creating an additional table and left joining could provide the most scalability (for non-query folding).
@txreal2
@txreal2 8 ай бұрын
Yes, tried this "creating an additional table and left joining could provide the most scalability" Thanks.
@clubedavid
@clubedavid 9 ай бұрын
Amazing video. I Start seeing M as a standard programming language instead of thinking of Chinese characters, thanks to you!
@Hortster
@Hortster 6 ай бұрын
I would approach this differently and have the conditions and commissions as a separate table which could be joined to your main table. That way you can keep it all dynamic rather than hard coding values into the advanced editor.
@paulwyatt8523
@paulwyatt8523 9 ай бұрын
Thank you Chandeep. What a fantastic technique. Until I discovered your content, I was concerned at how we might provide 'Certified' datasets because they still require the user to understand DAX in order to create their own 'self-service' measures and columns. You PQ SWITCH function is perfect for devs to create really rich 'certified' datasets that users can easily build with. I have a colleague who, after seeing the power of power Query through your techniques, has decided to work in PQ and not in SQL. You really change perceptions. You are also underpinning all of my own best practice solutions at the PQ level so, again, thank you.
@txreal2
@txreal2 9 ай бұрын
Except with large datasets 😊
@randomguy-jo1vq
@randomguy-jo1vq 9 ай бұрын
​@@txreal2that is true but with pq you need to be very cautious where to apply which resource intensive transformation step
@sandeepkhawas3367
@sandeepkhawas3367 9 ай бұрын
You are such an inspiration to thousands who are learning power bi..god bless you sir..!
@EricHartwigExcelConsulting
@EricHartwigExcelConsulting 9 ай бұрын
Excellent video! I watched this last night and forgot to comment. But I had so many ideas from watching this video!!
@spen2431
@spen2431 9 ай бұрын
💥💥 Nice one, and thanks for sharing. Not convinced it is "easier" than a conditional column though...
@GraceManinang-i2y
@GraceManinang-i2y Ай бұрын
I just wanna say, thank you. I am learning so much from you. You explained everything so clearly and I am always suprise that something that looks so complicated before is now comprehensive thanks to your awesome power bi communication skills.
@GoodlyChandeep
@GoodlyChandeep Ай бұрын
That's very kind of you to say! 🙏
@MyAvn
@MyAvn 7 ай бұрын
Thanks
@GoodlyChandeep
@GoodlyChandeep 9 ай бұрын
Download the file ⬇ - goodly.co.in/switch-function-power-query The Magic of Working with Lists in Power Query - kzbin.info/www/bejne/b2HEpYuXis11m8Usi=x49Gh1lgJ-Kse79o Tackle even the most challenging data-cleaning problems. Check out the M Language course and push beyond the user interface ↗ - goodly.co.in/learn-m-powerquery/
@KumarAnalytic
@KumarAnalytic 2 ай бұрын
In a folder I've so many Excel files and want to load into power query in one go as different data like Sales, Payroll, Attandance, Returns, Product etc. here I just want to load and I don't want to combine it. Thanks a lot Goodly!!
@mienzillaz
@mienzillaz 9 ай бұрын
Really nice example and I need to thank you not for this particular video, but for everything you did around PQ. Because of you (and BI Gorilla) I started to see PQ almost the way Neo saw the matrix 😅 You won't see bunch of views from me on this account, as I mostly watch you from company account 😂, but I'm there and I'm always recommending you as PQ guru. Keep it coming.
@cemisovs
@cemisovs 9 ай бұрын
Very good explanation and nice tricks. Thank you for the video! ❤
@barttitulaerexcelbart9400
@barttitulaerexcelbart9400 9 ай бұрын
Thanks. But if you don't need that so much, you can forget. My alternative: use "Column by Examples. It first starts with = but if you add more numbers at some point the "algortithm" displayst >=. You can then change some numbers in the formula. I don't know if it works all the time, but I just tried out. Looking forward to see your next video.
@kaidobor1
@kaidobor1 9 ай бұрын
Largest complexity in either approach right now is the redundancy of writing each threshold level twice. With nested if and switch you can avoid this, since after first match the result is selected and that's it. Switch statement does not require, that only one condition is true. With list approach you must provide complete condition, so only one result would match.
@megabuilds3007
@megabuilds3007 9 ай бұрын
I was unable to see the importance or efficiency of this approach over nested ifs. Explain please?
@frachiar4444
@frachiar4444 9 ай бұрын
me too. I tried to import a table of conditions and results, in order to make this more dinamic, but I failed :-( so, I do prefer nested if
@punit6490
@punit6490 9 ай бұрын
Error alert: added 6 results for 5 conditions. Anyways great stuff.
@rzvnpscl
@rzvnpscl 9 ай бұрын
Thanks for your videos, Chandeep. Is there any performance improvement with this approach?
@joaorataoo
@joaorataoo 9 ай бұрын
Your solution is brilliant and the way you make the explanation simple is amazing. When you were starting to present the solution, I thought you were going to suggest another solution which would be to create a function and call it within the query.
@roncruise4
@roncruise4 20 күн бұрын
Hello, Is the processing for this "switch" function any faster or slower than a true nested if? Or is it all the same? I use very long nested ifs on millions of lines and was wondering sbout the impact on processing time.
@laurentmarc1928
@laurentmarc1928 9 ай бұрын
Already splendid. Something really convenient in DAX Switch function is that the answer comes with the first TRUE answer. Would there be a tweak in this M code to give the position of the first TRUE in the list to even mimic better the DAX Switch? Maybe with a List.First ?
@shoaibrehman9988
@shoaibrehman9988 9 ай бұрын
I would say, its a gr8 solution, i hv been in situations and used many nested if, now thankful 🙏 for you. 🎉
@leemorgan8007
@leemorgan8007 9 ай бұрын
great video and clear instructions to use. Will check out your lists video too as I don't use them currently but think they will be incredibly valuable.
@dssmatus4962
@dssmatus4962 9 ай бұрын
This is amazing Chandeep, thanks for this. Is this somehow replicable in a way, that instead of hardcoding list, we can use some mapping file instead? Lets say, if another department is keeping excel with those commissions, and I am connecting this to my datamodel, I would like to automate this without me doing any maintenance of hardcoding
@ronaldtugume572
@ronaldtugume572 9 ай бұрын
Brilliant! How do you make it dynamic if the conditions change just as the discounts would equally change?
@kuuuyajim
@kuuuyajim 7 ай бұрын
Thank you for the wonderful explanation. I already have few use cases in mind while watching. 😀
@stefankirst3234
@stefankirst3234 9 ай бұрын
Watched this video almost immediately after it was posted and today I needed this exact thing. Once again: Thanks Chandeep! Awesome content :)
@GoodlyChandeep
@GoodlyChandeep 9 ай бұрын
Awesome! 😄
@kelemi4
@kelemi4 9 ай бұрын
Great video! Curious if you could make this into a user defined function with three inputs: a list of values, list of conditions and list of results that then could be reusable, would be interesting to modify for a default value if no conditions are met.
@miksosnowy1038
@miksosnowy1038 9 ай бұрын
you showed here also how to use something like index + match in excel in an easy way. I think this functionality is for me much more useful than swich. anyway great video, and as always very well explained :)
@kot23
@kot23 9 ай бұрын
Nice take on this scenario, I like that it uses lists & table logic instead of nested ifs, feels a lot more like Power Query that way. But is it more readable or user-friendly?
@RonDavidowicz
@RonDavidowicz 9 ай бұрын
Great video…any technique that gets rid of nested ifs is a good one! Question: how would you incorporate an Excel table of the different commission levels to make this more end user friendly?
@jamesclark2020
@jamesclark2020 9 ай бұрын
This is neat! Thank you. Power Query M is awesome 😎
@pamphlex
@pamphlex 9 ай бұрын
Great video, Does it process data faster than a nested if statement?
@ziggle314
@ziggle314 9 ай бұрын
Great work! M lists are so powerful. Thank you.
@jonathanheath8903
@jonathanheath8903 9 ай бұрын
Excellent video as usual, for a standard data set (int, text, etc) it’s great. I have to wonder if I can use the idea to test binary\table condition like Excel.Workbook(binarytotable) iserr true,false result being switch to ‘bad file’ or the normal [table]
@gauravguliani358
@gauravguliani358 9 ай бұрын
Not a problem in the first place I see that in a lot of your videos
@olivergarveigh8662
@olivergarveigh8662 9 ай бұрын
Your videos are really helpful. I've been able to really improve my powerbi skills so thank you :D Just a quick question if that's okay. I have watched your videos on creating fiscal years but I can't figure out how to get it to show the fiscal period in a line graph. Can you help pls?
@McIlravyInc
@McIlravyInc 8 ай бұрын
How can I do this in DAX looking between tables?
@ershelin
@ershelin 9 ай бұрын
Hello Dear, is it possible to add conditional column in PQ based on parameters from multiple columns. I am asking since it is not working with me. Thanks
@GoodlyChandeep
@GoodlyChandeep 9 ай бұрын
see this - stackoverflow.com/questions/31548135/power-query-transform-a-column-based-on-another-column
@ershelin
@ershelin 9 ай бұрын
@@GoodlyChandeep thanks for the feedback. problem resolved.
@prabhuji3337
@prabhuji3337 9 ай бұрын
Does this have any impact over processing speed? Amazing video once again!
@zahir585
@zahir585 9 ай бұрын
Brillante ❤ Keep up the hard work my friend✌
@DinoDelight
@DinoDelight 9 ай бұрын
What a great video, great explanation and example, thank you
@carlossv2945
@carlossv2945 9 ай бұрын
its Amazing the potental of powerquery, regards from Colombia
@alejandraseverino9240
@alejandraseverino9240 9 ай бұрын
Your video was very helpful, how can I apply this function if I'm using dates and in between and after specific date?
@Nalaka-Wanniarachchi
@Nalaka-Wanniarachchi 9 ай бұрын
Nice one 👍 One list lookup another list based on true condition.
@cdmkk2211
@cdmkk2211 9 ай бұрын
Can we get by multiplying the two list conditions and Result and sum them?????
@ПавелЛинев-ч7м
@ПавелЛинев-ч7м 9 ай бұрын
Отличный кейс. Спасибо. 👍👍
@chrism9037
@chrism9037 9 ай бұрын
Amazing! Thanks Chandeep!!!
@deda118
@deda118 9 ай бұрын
As a beginner, can’t see the benefit of this convoluted solution. But a a learning anyway, thank you.
@brij26579
@brij26579 9 ай бұрын
Awesome Use case 🤟 Goodly Rocks 👏
@SSi-nq3rt
@SSi-nq3rt 9 ай бұрын
Great 2nd solution, thank you. However, I am a bit unsure why i do not get the first solution of cond. column…. Why wouldn’t it work to add a simple conditional column but using the rule upside down? Like (If greater then 14500 then 0.25 else if greater then 14000 then 0.20 else if greater then 12000 then 0.15…) and so on? Rather then using a condition with „greater then A but smaller than B“? I am sure there is a reason but I can’t see it…
@vijayvizzu1
@vijayvizzu1 9 ай бұрын
Does the length of the both lists, need to be same? Means 1st contains 5 rows, and 2nd list 3 rows
@GoodlyChandeep
@GoodlyChandeep 9 ай бұрын
Yes
@GainerOP
@GainerOP 9 ай бұрын
Is there a way to have wildcards in your conditions? So a=1200 and b>4000, a=1200 and b=%
@raimundojs9547
@raimundojs9547 9 ай бұрын
Perfect! Awesome solution!
@jerrydellasala7643
@jerrydellasala7643 9 ай бұрын
Would love to see that as a function!
@arpankumar4487
@arpankumar4487 9 ай бұрын
Hi can you give me a solution why i'm not able to load xlsb file in powerquery window but same data i can load in xlsx format why it is happening.... in binary format file size reduce that's why we save file in binary format....
@aahanavikram07
@aahanavikram07 9 ай бұрын
Power query uses only xlsx file.
@KuldeepSingh-nq1vi
@KuldeepSingh-nq1vi 9 ай бұрын
Very Nice and Incredible Video Bro..
@boissierepascal5755
@boissierepascal5755 9 ай бұрын
Awsome and brillant use of lists.
@jimgleason4040
@jimgleason4040 9 ай бұрын
Awesome video as usual!
@indradutta4136
@indradutta4136 9 ай бұрын
Can you please show me to create a custom WE column using power query. I want start date of week should be Saturday.
@pthapa55
@pthapa55 9 ай бұрын
You are amazing, thank you for sharing.
@iankr
@iankr 9 ай бұрын
Very nice - many thanks!
@HussainAliNasser
@HussainAliNasser 9 ай бұрын
Nice video. Wouldn't you run into an error if more than 1 condition is true? If so, is there a workaround for that? SWITCH only evaluates the first true (or false) condition and returns the result.
@ThepExcel
@ThepExcel 9 ай бұрын
creative one. thx
@PranayPawar1991
@PranayPawar1991 9 ай бұрын
I still find "nested if" better in this case as it's adding too much of query folding. It is worth comparing how much time it takes in report refresh with a large dataset
@umesh2403
@umesh2403 9 ай бұрын
Amazing...❤
@eslamfahmy87
@eslamfahmy87 9 ай бұрын
🎉 creative 💡
@zdzislawkes
@zdzislawkes 9 ай бұрын
Hi, thank You very much for great content. I wonder what you said "something simillar to switch function" ;-) Maybe You thought about some functions with Your solution: fx_SWITCH( condition1, result1, condition2, result2, ... , else) ?
@pavelandreev6023
@pavelandreev6023 9 ай бұрын
Really nice! Tnx
@RavinderSingh-i6k
@RavinderSingh-i6k 9 ай бұрын
Nice as always :)
@RogerStocker
@RogerStocker 9 ай бұрын
<a href="#" class="seekto" data-time="143">2:23</a> Not sure but I guess the cases below 10000 would result in 25% commission, wouldn't it? I guess this was not the intension.
@markrobinson7492
@markrobinson7492 9 ай бұрын
is it just me, or anyone else think the NestedIF will just do fine here
@yaynative
@yaynative 9 ай бұрын
Probably depends on the scenario
@roncruise4
@roncruise4 6 ай бұрын
It's you. He's using a simple example to prove it works. For larger complex multi layered nested ifs, it makes sense to use this. My question: is it any faster or slower with millions of rows using this new way? Will it slow down any?
@shiholololo1053
@shiholololo1053 19 күн бұрын
​@roncruise4 Will probably slow down your query. With à nested-if, thou you perform n comparisons (n conditions), you only need to return 1 answer, this is a stored primitive type (boolean) and the query ends. This is as easy and low level as you can get. Using his method, you will need to to n comparisons and then store all these comparisons in memory as a list (no longer a primitive type, hence more space). You will them need to read the values from this list (list.positionof) and return the index. This here will slow your query. Reading from a list, even thou it is indexed, will still consume memory. And only after all of this can you return the index of the 2nd list, which is also stored in memory. Now all these operations and memory consumption for just a single row. Multiply that by m rows in your query, that will give you the space and time complexity of this method. I bet this is slower than multiple nested if statements, cuz they're primitive types and most languages including M, optimize for these operations. The only issue being to deal with the nested conditions. Heck, even a normal SWITCH statement in excel is just a glorified nested-if statement. There is elegance in simplicity. Hope it helped.
@dilipinamdarpatil6301
@dilipinamdarpatil6301 9 ай бұрын
Nice 🙏
@bimanroy8865
@bimanroy8865 9 ай бұрын
The catch all (*) condition is missing
@Acheiropoietos
@Acheiropoietos 9 ай бұрын
I find nested if statements very easy to use in m code
@pawewrona9749
@pawewrona9749 9 ай бұрын
I am not sure this approach makes things easier here. On top, I see another performance issue on top of the query folding point mentioned below. In your example you have 4 conditions to check, and even if the first condition is already satisfied, your approach still calculates remaining ones. This is unnecessary and doesn't happen when standard if is used. Still, your video shows how great Power Query is :)
@nitheshn7019
@nitheshn7019 9 ай бұрын
Thank you
@joaquimcosta952
@joaquimcosta952 9 ай бұрын
Amazing.
@JJ_TheGreat
@JJ_TheGreat 9 ай бұрын
Awesome!
@Rice0987
@Rice0987 9 ай бұрын
First formula is more simplier.😄
@GoodlyChandeep
@GoodlyChandeep 9 ай бұрын
True at the first instance. One could argue that.
@Rice0987
@Rice0987 9 ай бұрын
@@GoodlyChandeep but your example is very good for custom functions explanation.🤗
@ramakrishnaravula4350
@ramakrishnaravula4350 9 ай бұрын
Full video on new updates on Dax, power query and pivot
@Fannie2uN2010
@Fannie2uN2010 9 ай бұрын
Brilliant
@giorgitsomaia2812
@giorgitsomaia2812 9 ай бұрын
Super !!!
@manojkahar5718
@manojkahar5718 9 ай бұрын
I like this trick, Lot I use nested if. I will replace this trick
@pabeader1941
@pabeader1941 7 ай бұрын
Did you add the extra value to the second list just to see if anybody would comment on it? The last .35 has no real purpose...
@DeviChidambaram-w4m
@DeviChidambaram-w4m 9 ай бұрын
let Conditions = { [Amount] >= 1000 and [Amount] 10000 and [Amount] 14000 and [Amount] 20000 and [Amount] 30000 and [Amount] 50000 } , Boolean = List.Transform (Conditions , each if _ then 1 else 0), Results = {0.1,0.2,0.3,0.35,0.4,0.5} , ZipList = List.Zip ({Boolean,Results}) in List.Sum ( List.Transform ( ZipList,List.Product))
@salahaldeen7924
@salahaldeen7924 9 ай бұрын
how cool was that
@ershelin
@ershelin 9 ай бұрын
this is an awesome video. my below code worked well. however false conditions generates Error. let Conditions= { Text.Contains([Description],"STATIONERY"), Text.Contains([Description],"STATIONARY"), Text.Contains([Description],"FURNITURE"), Text.Contains([Description],"CHAIR"), Text.Contains([Description],"A4"), Text.Contains([Description],"HSE"), Text.Contains([Description],"GIFT") }, Results = {"CORPORATE","CORPORATE","CORPORATE","CORPORATE","CORPORATE","CORPORATE","CORPORATE"} in Results{List.PositionOf(Conditions,true)}
@GoodlyChandeep
@GoodlyChandeep 9 ай бұрын
The conditions need to be mutually exclusive
@ershelin
@ershelin 9 ай бұрын
@@GoodlyChandeep noted. however, I changed my approach. in my case "if/or/then/else if and else" works better and easy. well, your videos are very informative and saves my time
@ajaykumarthakur3207
@ajaykumarthakur3207 3 ай бұрын
@williamarthur4801
@williamarthur4801 9 ай бұрын
I thought you were going to zip them, I have a bit of an obsession with list zip.
@GoodlyChandeep
@GoodlyChandeep 9 ай бұрын
That would have produced a nested list. Hard to preview 😕
@darwisyb
@darwisyb 5 ай бұрын
I will delete all my queries and follow some from your videos lol
@sunilkumar8419
@sunilkumar8419 9 ай бұрын
Create video on febric pls
@farooqtahir538
@farooqtahir538 6 ай бұрын
Really this is an easy version than nested if???😂😂
@alexandrucoman1082
@alexandrucoman1082 2 ай бұрын
for anyone wanting to watch this video it s useless information about how to complicate a simple nested if statement into a really complex and really over complicated List statement and combine 2 lists and pick up from the lists whatever you need based on conditions and etc etc etc useless
@pk5134
@pk5134 9 ай бұрын
Great content as always! Is there a way you can use list.anytrue or list.alltrue for this?
@rjm50
@rjm50 2 ай бұрын
I have been using this since 2016 with the 1st version of "M is for (Data) Monkey. You define a simple function "fnSWITCH_HISTORIC" with your result/return pair combinations which you call from your query to the function. --------------------------------------------------------------------------------------------------------------------- (input) => // values A to L are items of [HERITAGE_BUILD_RIGHT] // translated to accepted historical designations. let values = { {"A", "NHLI"}, // National Historic Landmark, Individual {"B", "NRLI"}, // NRH Pics Lstd, Individual {"C", "NREI"}, // National Register Eligible, Individual {"D", "NCE"}, // Non-Con element Historic Property {"E", "DNE"}, // Determined not Eligible for List {"F", "NEV"}, // Not Evaluated {"G", "DNR"}, // Designation Rescinded {"H", "NHLC"}, // NHL Contributing Element {"I", "NRLC"}, // NRH Pics Lstd Contributing Element {"J", "NREC"}, // NRE Contributing Element {"K", "ELPA"}, // Eligible for purpose of PRG ALT {"L", "NAR"}, // Not Assessed Routinely {input, "UNKNOWN"} }, Result = List.First(List.Select(values, each _{0}=input)) {1} in Result ----------------------------------------------------------------------------------------------------------------- I then return one of the results: if fnSWITCH([HIST_Cd] = "A", returns to the calling query "National Historic Landmark, Individual". Simple enough.
Hilarious FAKE TONGUE Prank by WEDNESDAY😏🖤
0:39
La La Life Shorts
Рет қаралды 44 МЛН
번쩍번쩍 거리는 입
0:32
승비니 Seungbini
Рет қаралды 182 МЛН
Почему Катар богатый? #shorts
0:45
Послезавтра
Рет қаралды 2 МЛН
"Идеальное" преступление
0:39
Кик Брейнс
Рет қаралды 1,4 МЛН
5 Worst DAX Mistakes You’re Probably Making
15:53
Goodly
Рет қаралды 6 М.
Better than XLOOKUP? Try SUPERXLOOKUP!
11:39
Excel Off The Grid
Рет қаралды 52 М.
Line Chart | Level UP 📈
3:21
Let's talk Power BI
Рет қаралды 4,1 М.
List.Accumulate in Power Query with Practical Examples
27:26
Advanced Unpivoting Tricks in Power Query
30:19
Goodly
Рет қаралды 26 М.
Creating a SWITCH Function with Conditions in Power Query M
17:29
Hilarious FAKE TONGUE Prank by WEDNESDAY😏🖤
0:39
La La Life Shorts
Рет қаралды 44 МЛН