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
George1973
Helper V
Helper V

Product Grouping Index Problem

Hi All,

I have a following sample data table:

George1973_0-1675926416524.png

Here is it in Table form:

Prod_CodeFist_Sales_DateAnalog_GroupImportanceGroup_Prod_Code
Code_101-02-181 Code_2
Code_215-03-171SpectrumCode_2
Code_302-08-172 Code_7
Code_401-02-223 Code_4
Code_510-10-211 Code_2
Code_612-11-20  Code_6
Code_730-05-162SpectrumCode_7
Code_820-05-18  Code_8
Code_920-11-22  Code_9
Code_1020-05-183 Code_4

 

The goal is the get grouped the codes in the last column "Group_Prod_Code" based on following criteria:
1. Column "Analog_Group" represents groups among the set of product codes. Some of products may have "Analog Groups", but some may not
2. Within the Analog groups, there are some "Leading" products, called "Spectrum" (Column "Importance)
3. So, here are the final desired results to get:

3.1. If "Analog Group" has "Spectrum", then The "Group_Prod_Code" should be the one, which is generated from the "Spectrum product" within the group - This is the first criteria ((Example: Group#1 and 2)
3.2. If there is no "Spectrum", then the "Leading" product and respectively the "Group_Prod_Code" should be the product, with the latest "Sales Date". Column "First Sales Date" (Example: Group#3)
3.3. If there is no Analog_Group, then the End result for "Group_Product_Code" should be the same as the original product code

 

I Have managed to generate a "Calculated Column" grouping the analog_groups with only "Latest Sales Date", however I can not add the first criteria with "Spectrum" 😞

 

Analog_Leader_Code = 
VAR Vol=C_GOODS[ANALOG_GROUP]
VAR Miz=C_GOODS[MIZNIAN]
VAR MX=CALCULATE(max(C_GOODS[First Prod Sales Date]),FILTER(C_GOODS,C_GOODS[ANALOG_GROUP]=Vol))
Return
If(Vol=BLANK(),C_GOODS[Prod_Code],
    //if(Miz="Spectrum", IFERROR(LOOKUPVALUE(C_GOODS[პროდუქციის კოდი],C_GOODS[ANALOG_PROD_GROUP],Vol,C_GOODS[MIZNIAN],"Spectrum"),BLANK()),
    IFERROR(LOOKUPVALUE(C_GOODS[Prod_Code],C_GOODS[ANALOG_GROUP],Vol,C_GOODS[First Prod Sales Date],MX),BLANK())
    )

 


Thanks in advance,

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @George1973 

try to add a column like:

Group_Prod_Code2 = 
VAR _grouptable =
FILTER(
    GOODS,
    GOODS[Analog_Group] = EARLIER(GOODS[Analog_Group])
)
VAR _spectable =
FILTER( _grouptable, GOODS[Importance] = "Spectrum" )

VAR _condition1 =
COUNTROWS(_spectable)=1

VAR _speccode =
MINX( _spectable, GOODS[Prod_Code])

VAR _lastsalesdate =
MAXX(_grouptable, GOODS[Fist_Sales_Date])

VAR _lastsalescode =
MAXX( FILTER(_grouptable, GOODS[Fist_Sales_Date] =_lastsalesdate), GOODS[Prod_Code] )

RETURN
SWITCH(
    TRUE(),
    _condition1, _speccode,
    [Analog_Group]<>BLANK(), _lastsalescode,
    [Prod_Code]
)

 

it worked like:

FreemanZ_0-1675929430148.png

View solution in original post

3 REPLIES 3
wdx223_Daniel
Super User
Super User

Analog_Leader_Code =
VAR Vol=C_GOODS[ANALOG_GROUP]
RETURN

IF(Vol="",C_GOODS[Prod_Code],COALESCE(MAXX(FILTER(C_GOODS,C_GOODS[ANALOG_GROUP]=Vol&&C_GOODS[MIZNIAN]="Spectrum"),C_GOODS[Prod_Code]),MAXX(TOPN(1,FILTER(C_GOODS,C_GOODS[ANALOG_GROUP]=Vol),C_GOODS[First Prod Sales Date]),C_GOODS[Prod_Code])))

FreemanZ
Super User
Super User

hi @George1973 

try to add a column like:

Group_Prod_Code2 = 
VAR _grouptable =
FILTER(
    GOODS,
    GOODS[Analog_Group] = EARLIER(GOODS[Analog_Group])
)
VAR _spectable =
FILTER( _grouptable, GOODS[Importance] = "Spectrum" )

VAR _condition1 =
COUNTROWS(_spectable)=1

VAR _speccode =
MINX( _spectable, GOODS[Prod_Code])

VAR _lastsalesdate =
MAXX(_grouptable, GOODS[Fist_Sales_Date])

VAR _lastsalescode =
MAXX( FILTER(_grouptable, GOODS[Fist_Sales_Date] =_lastsalesdate), GOODS[Prod_Code] )

RETURN
SWITCH(
    TRUE(),
    _condition1, _speccode,
    [Analog_Group]<>BLANK(), _lastsalescode,
    [Prod_Code]
)

 

it worked like:

FreemanZ_0-1675929430148.png

Thanks a lot! Yes, it works now.

Great! 🙂

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.

Top Solution Authors