Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
alexproulx
New Member

Categorise item based on a text field (product category) and a number (its weight)

Hello,

 

I tried to find an answer but was not able to find anything.

English is a second language sorry if I'm unclear.

 

In PowerQuery, I'm trying to automatically categorize products based on their category and net weight.

 

Here is an example of the final result I'm trying to achieve :

 

SKUNiv1Niv2Niv3Net WeightSize
12FoodCatDry2.5Small
13FoodCatDry7Large
14FoodDogDry7Medium
15FoodDogDry15Large

 

Cat between 0 and 3 kg, it's a small bag, 3 and 8 it's a large bag.

But in the dog food i.e. 7kg is considered a medium bag.

 

I'm directly logged in to a material table in SAP via an OData link, but that information is not managed or maintained in SAP.

I initially tried to map every actual available size for each segment but as we create new SKUs, new weights are available so I would rather use a range logic.

 

Please let me know if there's any more information I can provide.

Thanks for the support

Best!

 

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

@alexproulx ,

 

You can create a table with the parameters and a custom column to calculate it.

 

Capture.PNGCapture.PNG

 

let 
_cat = [Niv2],
_weight = [Net Weight]
in
List.First(Table.SelectRows(TB_PARAMETERS, 
each 
[Niv2] = _cat and
[Max] >= _weight)[Label])


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

Proud to be a Super User!



View solution in original post

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @alexproulx ,

You can create a column like this:

Size = 
SWITCH (
    [Niv2],
    "Cat",
        SWITCH (
            TRUE (),
            [Net Weight] >= 0
                && [Net Weight] <= 3, "Small",
            [Net Weight] > 3
                && [Net Weight] <= 8, "Large"
        ),
    "Dog",
        SWITCH (
            TRUE (),
            [Net Weight] >= 0
                && [Net Weight] <= 3, "Small",
            [Net Weight] > 3
                && [Net Weight] <= 7, "Medium",
            [Net Weight] > 7, "Large"
        )
)

size.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

camargos88
Community Champion
Community Champion

@alexproulx ,

 

You can create a table with the parameters and a custom column to calculate it.

 

Capture.PNGCapture.PNG

 

let 
_cat = [Niv2],
_weight = [Net Weight]
in
List.First(Table.SelectRows(TB_PARAMETERS, 
each 
[Niv2] = _cat and
[Max] >= _weight)[Label])


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

Proud to be a Super User!



Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors