SWITCH Function in Power Query

SWITCH Function in Power Query

Goodly

7 месяцев назад

35,191 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@giorgitsomaia2812
@giorgitsomaia2812 - 07.03.2024 13:10

Super !!!

Ответить
@gauravguliani358
@gauravguliani358 - 07.03.2024 16:46

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

Ответить
@jerrydellasala7643
@jerrydellasala7643 - 07.03.2024 17:46

Would love to see that as a function!

Ответить
@miksosnowy1038
@miksosnowy1038 - 07.03.2024 20:41

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

Ответить
@EricHartwigExcelConsulting
@EricHartwigExcelConsulting - 07.03.2024 20:49

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

Ответить
@paulwyatt8523
@paulwyatt8523 - 07.03.2024 23:09

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.

Ответить
@laurentmarc1928
@laurentmarc1928 - 08.03.2024 05:16

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 ?

Ответить
@KuldeepSingh-nq1vi
@KuldeepSingh-nq1vi - 08.03.2024 05:56

Very Nice and Incredible Video Bro..

Ответить
@SSi-nq3rt
@SSi-nq3rt - 08.03.2024 08:14

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…

Ответить
@kot23
@kot23 - 08.03.2024 09:17

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?

Ответить
@jonathanheath8903
@jonathanheath8903 - 08.03.2024 13:53

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 - 08.03.2024 19:34

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

Ответить
@pk5134
@pk5134 - 09.03.2024 00:08

Great content as always!

Is there a way you can use list.anytrue or list.alltrue for this?

Ответить
@jamesclark2020
@jamesclark2020 - 09.03.2024 03:13

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

Ответить
@victor_wang_1
@victor_wang_1 - 09.03.2024 07:38

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

Ответить
@ПавелЛинев-ч7м
@ПавелЛинев-ч7м - 09.03.2024 11:21

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

Ответить
@pavelandreev6023
@pavelandreev6023 - 09.03.2024 14:12

Really nice! Tnx

Ответить
@olivergarveigh8662
@olivergarveigh8662 - 09.03.2024 16:44

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?

Ответить
@nitheshn7019
@nitheshn7019 - 09.03.2024 20:04

Thank you

Ответить
@joaorataoo
@joaorataoo - 10.03.2024 13:18

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.

Ответить
@manojkahar5718
@manojkahar5718 - 10.03.2024 14:49

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

Ответить
@indradutta4136
@indradutta4136 - 10.03.2024 22:31

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

Ответить
@RavinderSingh-i6k
@RavinderSingh-i6k - 11.03.2024 09:48

Nice as always :)

Ответить
@iankr
@iankr - 12.03.2024 17:41

Very nice - many thanks!

Ответить
@salahaldeen7924
@salahaldeen7924 - 12.03.2024 21:49

how cool was that

Ответить
@cemisovs
@cemisovs - 13.03.2024 17:43

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

Ответить
@ershelin
@ershelin - 14.03.2024 05:13

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

Ответить
@umesh2403
@umesh2403 - 15.03.2024 04:04

Amazing...❤

Ответить
@dilipinamdarpatil6301
@dilipinamdarpatil6301 - 15.03.2024 04:53

Nice 🙏

Ответить
@bimanroy8865
@bimanroy8865 - 16.03.2024 09:41

The catch all (*) condition is missing

Ответить
@ershelin
@ershelin - 16.03.2024 09:56

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

Ответить
@shoaibrehman9988
@shoaibrehman9988 - 16.03.2024 12:44

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

Ответить
@pawewrona9749
@pawewrona9749 - 17.03.2024 23:30

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

Ответить
@Fannie2uN2010
@Fannie2uN2010 - 18.03.2024 17:09

Brilliant

Ответить
@stefankirst3234
@stefankirst3234 - 19.03.2024 20:09

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

Ответить
@Acheiropoietos
@Acheiropoietos - 20.03.2024 00:47

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

Ответить
@deda118
@deda118 - 21.03.2024 14:31

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

Ответить
@alejandraseverino9240
@alejandraseverino9240 - 25.03.2024 15:15

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

Ответить
@barttitulaerexcelbart9400
@barttitulaerexcelbart9400 - 26.03.2024 22:53

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.

Ответить
@PranayPawar1991
@PranayPawar1991 - 30.03.2024 12:30

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 - 30.04.2024 16:54

How can I do this in DAX looking between tables?

Ответить
@MyAvn
@MyAvn - 07.05.2024 07:28

Thanks

Ответить
@pabeader1941
@pabeader1941 - 11.05.2024 13:23

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

Ответить
@kuuuyajim
@kuuuyajim - 27.05.2024 21:22

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

Ответить
@farooqtahir538
@farooqtahir538 - 06.06.2024 19:14

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

Ответить
@Hortster
@Hortster - 14.06.2024 03:31

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.

Ответить
@darwisyb
@darwisyb - 02.07.2024 04:15

I will delete all my queries and follow some from your videos lol

Ответить
@ajaykumarthakur3207
@ajaykumarthakur3207 - 19.09.2024 06:08

Ответить
@KumarAnalytic
@KumarAnalytic - 03.10.2024 03:31

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

Ответить
@rjm50
@rjm50 - 12.10.2024 06:36

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.

Ответить