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
Miguelcrz
Helper I
Helper I

Ayuda con combinaciones - DAX

Hola, estoy tratando de conocer las combinaciones más frecuentes de categorías de compra por cliente con DAX.

CategoríaClienteCantidad vendidaMarcaFecha
MaquillajeCliente A1Adidas01/01/2010
DermocosméticoCliente A2Regimiento01/01/2010
PielCliente B1Tommy02/02/2010
AccesoriosCliente B3Nike02/02/2010
TabletasCliente C1Aoc03/02/2010
MaquillajeCliente C1Adidas03/02/2010
DermocosméticoCliente C2Regimiento03/02/2010
CamisasCliente C1Regimiento03/02/2010

Combinaciones:

1. Maquillaje + Dermocosmético n.o 2 (del cliente C y del cliente A)

2. Piel + Accesorios 1

3. Tablets + Camisas 1

4. Tablets + Maquillaje 1

5. Tablets + Dermocosméticos 1

6. Tablets + Dermocosmética + Maquillaje + Camisas 1

Sé que puede tener un montón de combinaciones, pero también quiero saber si hay una manera de ver las combinaciones más frecuentes de 2 categorías.

Espero que puedas ayudarme.

¡Gracias! 😄

7 REPLIES 7
Greg_Deckler
Super User
Super User

Bien, creo que aquí es parte de la respuesta. Esto es una mesa.

Unique Product Combinations = 
    SELECTCOLUMNS(
        ADDCOLUMNS(
            ADDCOLUMNS(
                GENERATE(
                    GENERATE(
                        GENERATE(
                            SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category1",[Category]),
                            SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category2",[Category])
                        ),
                        SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category3",[Category])
                    ),
                    SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category4",[Category])
                ),
                "__Unique",COUNTROWS(DISTINCT({ [Category1], [Category2], [Category3], [Category4]}))
            ),
            "__Index",
                SWITCH(
                    [__Unique],
                    4,CONCATENATEX({[Category1],[Category2],[Category3],[Category4]},[Value],","),
                    3,CONCATENATEX({[Category1],[Category2],[Category3]},[Value],","),
                    2,CONCATENATEX({[Category1],[Category2]},[Value],","),
                    [Category1]
                )
        ),
        "Key",[__Index]
    )


@ 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...

Gracias @Greg_Deckler . He subido las 2 mesas que tengo para que puedas ayudarme con el dax.

¡Muchas gracias!

https://1drv.ms/x/s!AlnMWWMDdqtVlDF8M0d-ni5bEyD8?e=j11ZWU

Al examinar sus datos, ¿está interesado en distintas combinaciones de CATEGORY o SKU o ambos?


@ 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...

Me gustaría tener ambos si me ayudas, por favor.

¡¡Gracias!!

OK @Miguelcrz voy a echar un vistazo a los archivos. Mientras tanto, arreglé algunos errores en mi lógica, así que ahora sólo tengo combinaciones únicas, sin permutaciones donde las cosas se ordenan de manera diferente!! Se adjunta PBIX actualizado, aquí está el código:

Unique Product Combinations = 
    DISTINCT(
        SELECTCOLUMNS(
            ADDCOLUMNS(
                ADDCOLUMNS(
                    ADDCOLUMNS(
                        GENERATE(
                            GENERATE(
                                GENERATE(
                                    SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category1",[Category]),
                                    SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category2",[Category])
                                ),
                                SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category3",[Category])
                            ),
                            SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category4",[Category])
                        ),
                        "__Max",MAXX({[Category1],[Category2],[Category3],[Category4]},[Value]),
                        "__Min",MINX({[Category1],[Category2],[Category3],[Category4]},[Value])
                    ),
                    "__Mid1",MINX(FILTER({[Category1],[Category2],[Category3],[Category4]},[Value]<>[__Max]&&[Value]<>[__Min]),[Value]),
                    "__Mid2",MAXX(FILTER({[Category1],[Category2],[Category3],[Category4]},[Value]<>[__Max]&&[Value]<>[__Min]),[Value]),
                    "__Unique",COUNTROWS(DISTINCT({ [Category1], [Category2], [Category3], [Category4]}))
                ),
                "__Index",
                    SWITCH(
                        [__Unique],
                        4,CONCATENATEX({[__Min],[__Mid1],[__Mid2],[__Max]},[Value],","),
                        3,
                            VAR __Max = MAXX({[__Min],[__Mid1],[__Mid2],[__Max]},[Value])
                            VAR __Min = MINX({[__Min],[__Mid1],[__Mid2],[__Max]},[Value])
                            VAR __Mid = MAXX(FILTER({[__Min],[__Mid1],[__Mid2],[__Max]},[Value]<>__Max && [Value]<>__Min),[Value])
                            RETURN
                            CONCATENATEX({__Min,__Mid,__Max},[Value],","),
                        2,CONCATENATEX({[__Min],[__Max]},[Value],","),
                        [__Min]
                    )
            ),
            "Key",[__Index]
        )
    )


@ 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...

De acuerdo, casi. La tabla debe ser:

Unique Product Combinations = 
    DISTINCT(
        SELECTCOLUMNS(
            ADDCOLUMNS(
                ADDCOLUMNS(
                    GENERATE(
                        GENERATE(
                            GENERATE(
                                SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category1",[Category]),
                                SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category2",[Category])
                            ),
                            SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category3",[Category])
                        ),
                        SELECTCOLUMNS(DISTINCT('Table'[Category]),"Category4",[Category])
                    ),
                    "__Unique",COUNTROWS(DISTINCT({ [Category1], [Category2], [Category3], [Category4]}))
                ),
                "__Index",
                    SWITCH(
                        [__Unique],
                        4,CONCATENATEX({[Category1],[Category2],[Category3],[Category4]},[Value],","),
                        3,CONCATENATEX({[Category1],[Category2],[Category3]},[Value],","),
                        2,CONCATENATEX({[Category1],[Category2]},[Value],","),
                        [Category1]
                    )
            ),
            "Key",[__Index]
        )
    )


@ 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...

Bien, creo que esto está cerca. Creé esta tabla también:

Customer Unique Product Combinations = 
    DISTINCT(
        SELECTCOLUMNS(
            ADDCOLUMNS(
                ADDCOLUMNS(
                    GENERATE(
                        SUMMARIZE('Table',[Client],[Date]),
                        GENERATE(
                            GENERATE(
                                GENERATE(
                                    SELECTCOLUMNS(DISTINCT(SELECTCOLUMNS(FILTER('Table',[Client]=EARLIER('Table'[Client]) && [Date]=EARLIER('Table'[Date])),"Category",[Category])),"Category1",[Category]),
                                    SELECTCOLUMNS(DISTINCT(SELECTCOLUMNS(FILTER('Table',[Client]=EARLIER('Table'[Client]) && [Date]=EARLIER('Table'[Date])),"Category",[Category])),"Category2",[Category])
                                ),
                                 SELECTCOLUMNS(DISTINCT(SELECTCOLUMNS(FILTER('Table',[Client]=EARLIER('Table'[Client]) && [Date]=EARLIER('Table'[Date])),"Category",[Category])),"Category3",[Category])
                            ),
                             SELECTCOLUMNS(DISTINCT(SELECTCOLUMNS(FILTER('Table',[Client]=EARLIER('Table'[Client]) && [Date]=EARLIER('Table'[Date])),"Category",[Category])),"Category4",[Category])
                        )
                    ),
                    "__Unique",COUNTROWS(DISTINCT({ [Category1], [Category2], [Category3], [Category4]}))
                ),
                "__Index",
                    SWITCH(
                        [__Unique],
                        4,CONCATENATEX({[Category1],[Category2],[Category3],[Category4]},[Value],","),
                        3,CONCATENATEX({[Category1],[Category2],[Category3]},[Value],","),
                        2,CONCATENATEX({[Category1],[Category2]},[Value],","),
                        [Category1]
                    )
            ),
            "Client",[Client],
            "Key",[__Index]
        )
    )

Se ha creado esta columna en Combinaciones de productos únicos:

Column = COUNTROWS(RELATEDTABLE('Customer Unique Product Combinations'))

Creo que está cerca, probablemente todavía necesita algo de trabajo para deshacerse de duplicados como maquillaje, maquillaje, camisa tipo de cosas. PBIX está unido.


@ 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...

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.