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
Ugot2Bsh1tingMe
New Member

How to create a column based off the values in other columns

Hello,

 

I have a table that contains, among other things, order numbers, and order stop sequences. What I would like to achieve is to create a column that distinguishes based on stop sequence if that stop is the origin, destination, or stop-off. Determining the origin is easy because the stop sequence is always 1. Attempts to identify the destination, though, have not been successful. Example 1 below shows some mock data with three different order numbers but the number of stops varies. Example 2 is what I would like to achieve if possible. Any help would be greatly appreciated. 

 

Example 1:

Order NumberOrder Stop Sequence
1012211
1012212
1012213
4442221
4442222
3331111
3331112
3331113
3331114

Example 2:

Order NumberOrder Stop SequenceType of Stop
1012211Origin
1012212Stop Off
1012213Destination
4442221Origin
4442222Destination
3331111Origin
3331112Stop Off
3331113Stop Off
3331114Destination

 

1 ACCEPTED SOLUTION
v-kaiyue-msft
Community Support
Community Support

Hi @Ugot2Bsh1tingMe ,

Thanks to @mahenkj2  for the reply, please allow me to provide another insight:
You can create a calculated column and then use the switch function to get the desired result.

Column =
VAR _max = CALCULATE(MAX('Table'[Order Stop Sequence]),FILTER(ALL('Table'),'Table'[Order Number] = EARLIER('Table'[Order Number])))
RETURN
SWITCH(TRUE(),
'Table'[Order Stop Sequence] = 1,"Origin",
'Table'[Order Stop Sequence] = _max,"Destination",
"Stop Off")

vkaiyuemsft_0-1713495915990.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Ugot2Bsh1tingMe
New Member

Thank you all for your help! Both solutions listed did work. Mahenkj2, thank you for pointing out some information that would have clarified my request. I'll (try to, lol) be sure and be more clear in future requests. Again, thanks to all. 

 

Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

Column = if(Data[Order Stop Sequence]=1,"Origin",if(CALCULATE(MAX(Data[Order Stop Sequence]),FILTER(Data,Data[Order Number]=EARLIER(Data[Order Number])))=Data[Order Stop Sequence],"Destination","Stop off"))

Hope this helps.

Ashish_Mathur_0-1713497177770.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-kaiyue-msft
Community Support
Community Support

Hi @Ugot2Bsh1tingMe ,

Thanks to @mahenkj2  for the reply, please allow me to provide another insight:
You can create a calculated column and then use the switch function to get the desired result.

Column =
VAR _max = CALCULATE(MAX('Table'[Order Stop Sequence]),FILTER(ALL('Table'),'Table'[Order Number] = EARLIER('Table'[Order Number])))
RETURN
SWITCH(TRUE(),
'Table'[Order Stop Sequence] = 1,"Origin",
'Table'[Order Stop Sequence] = _max,"Destination",
"Stop Off")

vkaiyuemsft_0-1713495915990.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

mahenkj2
Solution Sage
Solution Sage

Hi @Ugot2Bsh1tingMe ,

 

So type of stop does not depend on order stop sequence, 1 is always origin, but 2 can be destination or stop off, likewise 3 can also be stop off or destination.

 

So then type of stop dependent on what, order number? Pls confirm logic clearly.

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.