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

Deleting (or merge) Products from a Basket - Basket Analysis

Hello!

 

I’ve been trying how to avoid the “Duplicate basket” In my Power BI project. The situation is that I’ve a dataset with transaction and I want to create a Basket. So, for example, I’ve this dataset:Excel.JPG

 

As you notice the basket is the same but the order is different. So, when I write the Dax Formula:

Canasta = 
CALCULATE (
    CONCATENATEX ( Ventas; Ventas[Product ID]; "-" );
    FILTER (
        ALL ( Ventas );
        Ventas[Transaction ID] = EARLIER ( Ventas[Transaction ID] )
    )
)

 

 

And i obtain this result:Dos Canasta.JPG

 

 

And when I create a new table without the duplicate I’ve two baskets and I should have one (In theory, because the problem is that I don’t kwon how to compare the Texts) So I’ve this result:Diferente.JPG

 

 

There is a way where I can filter o make another calculation to integrate the two baskets only in one.

 

The Power BI project is here: https://files.fm/u/bd5q2v23

 

Thanks!

1 ACCEPTED SOLUTION

Hi joaco ,

 

To achieve your requirement, first create a ranking column based on each Transaction ID group using DAX below:

Rank =
RANKX (
FILTER ( Ventas, Ventas[Transaction ID] = EARLIER ( Ventas[Transaction ID] ) ),
RANKX ( ALL ( Ventas ), Ventas[Product ID] ),
,
ASC,
DENSE
)

Then create a calculate column Canasta using DAX like this and check if it can meet your requirement.

Canasta =
IF (
    CALCULATE (
        COUNTROWS ( Ventas ),
        FILTER (
            Ventas,
            Ventas[Rank] = EARLIER ( Ventas[Rank] )
                && Ventas[Product ID] <> EARLIER ( Ventas[Product ID] )
        )
    )
        = 0,
    CONCATENATEX ( VALUES ( Ventas[Product ID] ), Ventas[Product ID], "-" ),
    CALCULATE (
        CONCATENATEX ( Ventas, Ventas[Product ID], "-" ),
        FILTER (
            ALL ( Ventas ),
            Ventas[Transaction ID] = EARLIER ( Ventas[Transaction ID] )
        )
    )
)

Hope it's helpful to you.

 

Regards,

Jimmy Tao

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

Perhaps if you do a Sort by your Product ID column in your query, then when you concatenate the values they will be in the same order?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

and how should I do that? Do you have any link where I can see a way to sort the columns how do you say it?

Thanks!

Hi joaco ,

 

To achieve your requirement, first create a ranking column based on each Transaction ID group using DAX below:

Rank =
RANKX (
FILTER ( Ventas, Ventas[Transaction ID] = EARLIER ( Ventas[Transaction ID] ) ),
RANKX ( ALL ( Ventas ), Ventas[Product ID] ),
,
ASC,
DENSE
)

Then create a calculate column Canasta using DAX like this and check if it can meet your requirement.

Canasta =
IF (
    CALCULATE (
        COUNTROWS ( Ventas ),
        FILTER (
            Ventas,
            Ventas[Rank] = EARLIER ( Ventas[Rank] )
                && Ventas[Product ID] <> EARLIER ( Ventas[Product ID] )
        )
    )
        = 0,
    CONCATENATEX ( VALUES ( Ventas[Product ID] ), Ventas[Product ID], "-" ),
    CALCULATE (
        CONCATENATEX ( Ventas, Ventas[Product ID], "-" ),
        FILTER (
            ALL ( Ventas ),
            Ventas[Transaction ID] = EARLIER ( Ventas[Transaction ID] )
        )
    )
)

Hope it's helpful to you.

 

Regards,

Jimmy Tao

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.