SWITCH Function in Power Query

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 มี.ค. 2024
  • • The Magic of Working w...
    In this video, I'll show you a simple way to imitate the SWITCH function in Power Query. Since Power Query doesn't have this function, I'll demonstrate an easy technique that mimics it, helping you avoid complex nested IF statements.
    #PowerQuery #DataCleaning #NestedIf
    ===== ONLINE COURSES =====
    ✔️ Master 'M' in Power Query -
    goodly.co.in/learn-m-powerquery/
    ✔️ Mastering DAX in Power BI -
    goodly.co.in/learn-dax-powerbi/
    ✔️ Power Query Course-
    goodly.co.in/learn-power-query/
    ✔️ Master Excel Step-by-Step-
    goodly.co.in/learn-excel/
    ✔️ Business Intelligence Dashboards-
    goodly.co.in/learn-excel-dash...
    ===== LINKS 🔗 =====
    Blog 📰 - www.goodly.co.in/blog/
    Corporate Training 👨‍🏫 - www.goodly.co.in/training/
    Need my help on a Project 💻- www.goodly.co.in/consulting/
    Download File ⬇️ - goodly.co.in/switch-function-...
    ===== CONTACT 🌐 =====
    Twitter - / chandeep2786
    LinkedIn - / chandeepchhabra
    Email - goodly.wordpress@gmail.com
    ===== WHO AM I? =====
    A lot of people think that my name is Goodly, it's NOT ;)
    My name is Chandeep. Goodly is my full-time venture where I share what I learn about Excel and Power BI.
    Please browse around, you'll find a ton of interesting videos that I have created :) Cheers!
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 105

  • @victor_wang_1
    @victor_wang_1 3 หลายเดือนก่อน +19

    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 หลายเดือนก่อน

      Yes, tried this "creating an additional table and left joining could provide the most scalability"
      Thanks.

  • @greisboy425
    @greisboy425 3 หลายเดือนก่อน +7

    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.

  • @clubedavid
    @clubedavid 3 หลายเดือนก่อน +9

    Amazing video. I Start seeing M as a standard programming language instead of thinking of Chinese characters, thanks to you!

  • @punit6490
    @punit6490 3 หลายเดือนก่อน +8

    Error alert: added 6 results for 5 conditions. Anyways great stuff.

  • @spen2431
    @spen2431 3 หลายเดือนก่อน +9

    💥💥 Nice one, and thanks for sharing. Not convinced it is "easier" than a conditional column though...

  • @kuuuyajim
    @kuuuyajim 17 วันที่ผ่านมา

    Thank you for the wonderful explanation. I already have few use cases in mind while watching. 😀

  • @sandeepkhawas3367
    @sandeepkhawas3367 3 หลายเดือนก่อน +3

    You are such an inspiration to thousands who are learning power bi..god bless you sir..!

  • @barttitulaerexcelbart9400
    @barttitulaerexcelbart9400 2 หลายเดือนก่อน +1

    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.

  • @EricHartwigConsulting
    @EricHartwigConsulting 3 หลายเดือนก่อน +1

    Excellent video!
    I watched this last night and forgot to comment. But I had so many ideas from watching this video!!

  • @ziggle314
    @ziggle314 3 หลายเดือนก่อน

    Great work! M lists are so powerful. Thank you.

  • @mienzillaz
    @mienzillaz 3 หลายเดือนก่อน +1

    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.

  • @paulwyatt8523
    @paulwyatt8523 3 หลายเดือนก่อน +1

    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 3 หลายเดือนก่อน

      Except with large datasets 😊

    • @randomguy-jo1vq
      @randomguy-jo1vq 3 หลายเดือนก่อน

      ​@@txreal2that is true but with pq you need to be very cautious where to apply which resource intensive transformation step

  • @raimundojs9547
    @raimundojs9547 3 หลายเดือนก่อน

    Perfect! Awesome solution!

  • @DinoDelight
    @DinoDelight 3 หลายเดือนก่อน

    What a great video, great explanation and example, thank you

  • @cemisovs
    @cemisovs 3 หลายเดือนก่อน +1

    Very good explanation and nice tricks. Thank you for the video! ❤

  • @carlossv2945
    @carlossv2945 3 หลายเดือนก่อน

    its Amazing the potental of powerquery, regards from Colombia

  • @chrism9037
    @chrism9037 3 หลายเดือนก่อน

    Amazing! Thanks Chandeep!!!

  • @boissierepascal5755
    @boissierepascal5755 3 หลายเดือนก่อน

    Awsome and brillant use of lists.

  • @jamesclark2020
    @jamesclark2020 3 หลายเดือนก่อน

    This is neat! Thank you. Power Query M is awesome 😎

  • @pthapa55
    @pthapa55 3 หลายเดือนก่อน

    You are amazing, thank you for sharing.

  • @iankr
    @iankr 3 หลายเดือนก่อน

    Very nice - many thanks!

  • @jimgleason4040
    @jimgleason4040 3 หลายเดือนก่อน

    Awesome video as usual!

  • @user-yo2nb4ry7i
    @user-yo2nb4ry7i 3 หลายเดือนก่อน

    Отличный кейс. Спасибо. 👍👍

  • @shoaibrehman9988
    @shoaibrehman9988 3 หลายเดือนก่อน

    I would say, its a gr8 solution, i hv been in situations and used many nested if, now thankful 🙏 for you. 🎉

  • @zahir585
    @zahir585 3 หลายเดือนก่อน

    Brillante ❤ Keep up the hard work my friend✌

  • @brij26579
    @brij26579 3 หลายเดือนก่อน

    Awesome Use case 🤟 Goodly Rocks 👏

  • @pavelandreev6023
    @pavelandreev6023 3 หลายเดือนก่อน

    Really nice! Tnx

  • @leemorgan8007
    @leemorgan8007 3 หลายเดือนก่อน

    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.

  • @kaidobor1
    @kaidobor1 3 หลายเดือนก่อน +2

    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.

  • @Hortster
    @Hortster 9 ชั่วโมงที่ผ่านมา

    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.

  • @KuldeepSingh-nq1vi
    @KuldeepSingh-nq1vi 3 หลายเดือนก่อน

    Very Nice and Incredible Video Bro..

  • @joaorataoo
    @joaorataoo 3 หลายเดือนก่อน

    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.

  • @umesh2403
    @umesh2403 3 หลายเดือนก่อน

    Amazing...❤

  • @rzvnpscl
    @rzvnpscl 3 หลายเดือนก่อน +2

    Thanks for your videos, Chandeep. Is there any performance improvement with this approach?

  • @GoodlyChandeep
    @GoodlyChandeep  3 หลายเดือนก่อน +1

    Download the file ⬇ - goodly.co.in/switch-function-power-query
    The Magic of Working with Lists in Power Query - th-cam.com/video/90atXaUhBec/w-d-xo.htmlsi=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/

  • @ThepExcel
    @ThepExcel 3 หลายเดือนก่อน

    creative one. thx

  • @giorgitsomaia2812
    @giorgitsomaia2812 3 หลายเดือนก่อน

    Super !!!

  • @Nalaka-Wanniarachchi
    @Nalaka-Wanniarachchi 3 หลายเดือนก่อน +1

    Nice one 👍
    One list lookup another list based on true condition.

  • @nitheshn7019
    @nitheshn7019 3 หลายเดือนก่อน

    Thank you

  • @stefankirst3234
    @stefankirst3234 2 หลายเดือนก่อน

    Watched this video almost immediately after it was posted and today I needed this exact thing. Once again: Thanks Chandeep! Awesome content :)

  • @JJ_TheGreat
    @JJ_TheGreat 3 หลายเดือนก่อน

    Awesome!

  • @user-dt5cy1vr2t
    @user-dt5cy1vr2t 3 หลายเดือนก่อน

    Nice as always :)

  • @eslamfahmy87
    @eslamfahmy87 3 หลายเดือนก่อน

    🎉 creative 💡

  • @joaquimcosta952
    @joaquimcosta952 3 หลายเดือนก่อน

    Amazing.

  • @gauravguliani358
    @gauravguliani358 3 หลายเดือนก่อน +1

    Not a problem in the first place
    I see that in a lot of your videos

  • @Fannie2uN2010
    @Fannie2uN2010 2 หลายเดือนก่อน

    Brilliant

  • @MyAvn
    @MyAvn หลายเดือนก่อน

    Thanks

  • @miksosnowy1038
    @miksosnowy1038 3 หลายเดือนก่อน

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

  • @jerrydellasala7643
    @jerrydellasala7643 3 หลายเดือนก่อน

    Would love to see that as a function!

  • @dilipinamdarpatil6301
    @dilipinamdarpatil6301 3 หลายเดือนก่อน

    Nice 🙏

  • @RonDavidowicz
    @RonDavidowicz 3 หลายเดือนก่อน

    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?

  • @dssmatus4962
    @dssmatus4962 3 หลายเดือนก่อน +1

    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

  • @jonathanheath8903
    @jonathanheath8903 3 หลายเดือนก่อน

    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]

  • @ronaldtugume572
    @ronaldtugume572 3 หลายเดือนก่อน

    Brilliant! How do you make it dynamic if the conditions change just as the discounts would equally change?

  • @kelemi4
    @kelemi4 3 หลายเดือนก่อน +1

    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.

  • @pamphlex
    @pamphlex 3 หลายเดือนก่อน

    Great video, Does it process data faster than a nested if statement?

  • @megabuilds3007
    @megabuilds3007 3 หลายเดือนก่อน +4

    I was unable to see the importance or efficiency of this approach over nested ifs. Explain please?

    • @frachiar4444
      @frachiar4444 3 หลายเดือนก่อน

      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

  • @kot23
    @kot23 3 หลายเดือนก่อน

    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?

  • @markrobinson7492
    @markrobinson7492 3 หลายเดือนก่อน +5

    is it just me, or anyone else think the NestedIF will just do fine here

    • @yaynative
      @yaynative 3 หลายเดือนก่อน

      Probably depends on the scenario

  • @laurentmarc1928
    @laurentmarc1928 3 หลายเดือนก่อน

    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 ?

  • @prabhuji3337
    @prabhuji3337 3 หลายเดือนก่อน

    Does this have any impact over processing speed? Amazing video once again!

  • @deda118
    @deda118 2 หลายเดือนก่อน

    As a beginner, can’t see the benefit of this convoluted solution. But a a learning anyway, thank you.

  • @olivergarveigh8662
    @olivergarveigh8662 3 หลายเดือนก่อน

    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?

  • @alejandraseverino9240
    @alejandraseverino9240 2 หลายเดือนก่อน

    Your video was very helpful, how can I apply this function if I'm using dates and in between and after specific date?

  • @cdmkk2211
    @cdmkk2211 3 หลายเดือนก่อน

    Can we get by multiplying the two list conditions and Result and sum them?????

  • @GainerOP
    @GainerOP 3 หลายเดือนก่อน

    Is there a way to have wildcards in your conditions? So a=1200 and b>4000, a=1200 and b=%

  • @zdzislawkes
    @zdzislawkes 3 หลายเดือนก่อน

    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) ?

  • @PranayPawar1991
    @PranayPawar1991 2 หลายเดือนก่อน

    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

  • @McIlravyInc
    @McIlravyInc หลายเดือนก่อน

    How can I do this in DAX looking between tables?

  • @HussainAliNasser
    @HussainAliNasser 3 หลายเดือนก่อน

    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.

  • @salahaldeen7924
    @salahaldeen7924 3 หลายเดือนก่อน

    how cool was that

  • @manojkahar5718
    @manojkahar5718 3 หลายเดือนก่อน

    I like this trick, Lot I use nested if. I will replace this trick

  • @Acheiropoietos
    @Acheiropoietos 2 หลายเดือนก่อน

    I find nested if statements very easy to use in m code

  • @SSi-nq3rt
    @SSi-nq3rt 3 หลายเดือนก่อน

    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…

  • @indradutta4136
    @indradutta4136 3 หลายเดือนก่อน

    Can you please show me to create a custom WE column using power query. I want start date of week should be Saturday.

  • @vijayvizzu1
    @vijayvizzu1 3 หลายเดือนก่อน

    Does the length of the both lists, need to be same? Means 1st contains 5 rows, and 2nd list 3 rows

  • @ershelin
    @ershelin 3 หลายเดือนก่อน

    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  3 หลายเดือนก่อน

      see this - stackoverflow.com/questions/31548135/power-query-transform-a-column-based-on-another-column

    • @ershelin
      @ershelin 3 หลายเดือนก่อน

      @@GoodlyChandeep thanks for the feedback. problem resolved.

  • @ramakrishnaravula4350
    @ramakrishnaravula4350 3 หลายเดือนก่อน

    Full video on new updates on Dax, power query and pivot

  • @pawewrona9749
    @pawewrona9749 2 หลายเดือนก่อน

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

  • @arpankumar4487
    @arpankumar4487 3 หลายเดือนก่อน

    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 3 หลายเดือนก่อน

      Power query uses only xlsx file.

  • @Rice0987
    @Rice0987 3 หลายเดือนก่อน +1

    First formula is more simplier.😄

    • @GoodlyChandeep
      @GoodlyChandeep  3 หลายเดือนก่อน +1

      True at the first instance. One could argue that.

    • @Rice0987
      @Rice0987 3 หลายเดือนก่อน

      @@GoodlyChandeep but your example is very good for custom functions explanation.🤗

  • @bimanroy8865
    @bimanroy8865 3 หลายเดือนก่อน

    The catch all (*) condition is missing

  • @user-zt6ir9wp3z
    @user-zt6ir9wp3z 3 หลายเดือนก่อน +2

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

  • @ershelin
    @ershelin 3 หลายเดือนก่อน

    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  3 หลายเดือนก่อน

      The conditions need to be mutually exclusive

    • @ershelin
      @ershelin 2 หลายเดือนก่อน

      @@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

  • @RogerStocker
    @RogerStocker 3 หลายเดือนก่อน

    2:23 Not sure but I guess the cases below 10000 would result in 25% commission, wouldn't it? I guess this was not the intension.

  • @williamarthur4801
    @williamarthur4801 3 หลายเดือนก่อน

    I thought you were going to zip them, I have a bit of an obsession with list zip.

    • @GoodlyChandeep
      @GoodlyChandeep  3 หลายเดือนก่อน

      That would have produced a nested list. Hard to preview 😕

  • @pabeader1941
    @pabeader1941 หลายเดือนก่อน

    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...

  • @sunilkumar8419
    @sunilkumar8419 3 หลายเดือนก่อน

    Create video on febric pls

  • @farooqtahir538
    @farooqtahir538 7 วันที่ผ่านมา

    Really this is an easy version than nested if???😂😂

  • @pk5134
    @pk5134 3 หลายเดือนก่อน

    Great content as always!
    Is there a way you can use list.anytrue or list.alltrue for this?