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
aaron_lee
Frequent Visitor

Assign an index by row in a new column based on multiple criteria

Hi,

 

I am looking for some help with building 2 new columns in my dataset.  They are:

 

  1. Assign an index to each product based on a combination of variables from otherc olumns. This is desired output 1
  2. Desired Output2 -  The minimum price for each new group that has been created in desired output 1.

Example:

Power Bi.PNG

 

 

 

 

 

 

 

 

 

 

 

For desired output 1 i need to find all of the products that are related to each other. See colour coded groups above. I have used the folloing formula but it doesnt give the right result. 

Desired Output 1 = CALCULATE(MINX(testdata,testdata[Group 1]),FILTER(testdata,testdata[Group 2] = EARLIER(testdata[Group 2])))

 

In SQL we use a CASE statement with PARTION BY to generate the desired output. We would like to use Power BI however as it offers more flexibility.

 

It may be that a measure rather than column is a better alternative. Open to suggestions and would like some help please

 

Thanks

 

Aaron

 

 

 

5 REPLIES 5
JarroVGIT
Resident Rockstar
Resident Rockstar

Can you explain what the logic is behind DesiredOutput1? Is it - if both values in group1 and group2 haven't occured yet in the table, then up the index by 1?

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




yes.

I want to create an index or unique number for groups of products that feature in both group 1 and group 2.

To give some context to the numbers in the table. Group 1 are products that are same type (ie crisps) and size (1 is small small crisps and 2 is large). Group 2 binds the groups together by linking the different sizes to the unique flavours (ie group 3 are small and large salted crisps ). The group then puts together all flavours of small and large crisps. Think pringles...

You can see from the table Group1 products that are either denoted by a 1 or 2 are related in Group 2 in some way. The index/unique number I am trying to create is in effect the super group.

Hope this makes sense and thanks for the response.

Thanks for trying to clarify the question. I still don't fully understand the logic of grouping the products together based on Group1 and Group2. I understand that the numbers in both columns are reflecting categories from the same list of categories?

Is there a hard mapping between group1 and desiredOutput1? For example: you want to group products from Group1=1 && Group1=2 together, and you want to group products from Group1=emtpy together, and you want to group products from Group1=8 together? If that is hardcoded then you can create a calculated column with Switch:

DesiredOutput1 = SWITCH([Group1], 1, 1, 
                  2, 1, 
                 "", 2, 
                  8, 3)  

Your desiredoutput2 can then be:

DesiredOutout2 = 
VAR currentGroup = Table1[DesiredOutput1]
RETURN
CALCULATE(MIN(Table1[New Price]), FILTER(Table1, Table1[DesiredOutput1] = currentGroup))

 

Hope this helps you out? Let me know! 🙂

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks for the response. Yes the products are in the same product category. 

There are too many groups (1 & 2) to hard code the result (200+ in each). Plus, the products in the groups change weekly so think the solution needs to be dynamic i.e. cycle through all of the combinations in 1 & 2 to build the desired output. 

I've updated the example to help provide some more context

Product IdProduct DetailGroup 1
(Same Size & Different Flavour)
Group 2
(Different Size & Same Flavour)
CombinationDesired Out Put1
(Super Group)
4Small Crisps - Plain1 1,1
7Small Crisps - BBQ131,31
17Large Crisps - BBQ232,31
12Small Crisps - Chilli141,41
13Large Crisps - Chilli242,41
11Small Crisps - Cheese151,51
14Large Crisps - Cheese252,51
9Small Crisps - Salted161,61
15Large Crisps - Salted262,61
16Large Crisps - Tangy2 2,1
18Yoghurt---,-2
24Milk Full Fat8-8,-3
20Mulik Semi Skimmed8-8,-3
21Carrot---,-4
200Burger---,-98
250Cheese---,-100
 

For the crisps group. I have re-sorted the example to better show how the products relate to each other in terms of product size and flavour. Where there isnt different sizes of a flavour i.e. Small plain and Large tangy, these are still part of the desired output as they are part of Grouping 1 where other flavours are bound to group 2 through different sizes 

 

I hope this makes sense

I forgot to say i should have made it clear that my example was just an exmple rather than the total dataset. Apologies!

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.