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
Anonymous
Not applicable

Categorize Cargo Destination based on Previous Historical Data

Hello all, 

 

I require an assistance regarding a categorization calculated column I am creating. I am trying to do this in DAX, but if there are any workareound, it would be great.

 

Below is my issue, I have 3 columns in the dataset, cargo , customer name and location. I would like to create another column that:

 

1. would repeat the Location if not Blank

2. If blank , would analyze how many times a location was used for the same customer, rank it and assign the most used one.

3. In case that there are customers that had same number of cargoes sent to different locations , choose one based on the alphabetical sequence (A-Z)

 

CargoCustomer NameLocationDesired Calculated Column
AMarkAsiaAsia
BMarkAsiaAsia
CMarkEuropeEurope
DMarkBlankAsia (based on the other data, Asia was the highest sent Location)
ELouisAsiaAsia
FLouisAsiaAsia
GLouisBlankAsia (based on the other data, Asia was the highest sent Location)
HJulieEuropeEurope
IJulieAmericaAmerica
JJulieBlankAmerica (it is 50 50 for America and Europe, so consider the first one (based on A-Z)

 

Thank you in advance!

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@Anonymous create this calculated column:

 

Column = 
IF(
    'Table'[Location] <> "", 'Table'[Location],
    VAR _current_customer = 'Table'[Customer Name]
    VAR _tbl = 
    CALCULATETABLE(
        ADDCOLUMNS(
            VALUES('Table'[Location]),
            "@Cargos", CALCULATE(COUNTROWS('Table'))
        ),
        'Table'[Customer Name] = _current_customer,
        'Table'[Location] <> "",
        REMOVEFILTERS('Table')
    )
    VAR _max_cargos = MAXX(_tbl, [@Cargos])
    VAR _filtered_tbl = FILTER(_tbl, [@Cargos] = _max_cargos)
    VAR _remove_equals = TOPN(1,_filtered_tbl, 'Table'[Location] , ASC)
    VAR _result = CONCATENATEX(_remove_equals, 'Table'[Location])
    RETURN
        _result
)

 

SpartaBI_0-1655993868746.png

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

View solution in original post

1 REPLY 1
SpartaBI
Community Champion
Community Champion

@Anonymous create this calculated column:

 

Column = 
IF(
    'Table'[Location] <> "", 'Table'[Location],
    VAR _current_customer = 'Table'[Customer Name]
    VAR _tbl = 
    CALCULATETABLE(
        ADDCOLUMNS(
            VALUES('Table'[Location]),
            "@Cargos", CALCULATE(COUNTROWS('Table'))
        ),
        'Table'[Customer Name] = _current_customer,
        'Table'[Location] <> "",
        REMOVEFILTERS('Table')
    )
    VAR _max_cargos = MAXX(_tbl, [@Cargos])
    VAR _filtered_tbl = FILTER(_tbl, [@Cargos] = _max_cargos)
    VAR _remove_equals = TOPN(1,_filtered_tbl, 'Table'[Location] , ASC)
    VAR _result = CONCATENATEX(_remove_equals, 'Table'[Location])
    RETURN
        _result
)

 

SpartaBI_0-1655993868746.png

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

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.