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
joerykeizer
Helper II
Helper II

Measure for most recurring value

Hi all,

 

I have a customer table and a purchase order table. 

 

For each customer I would like to create a measure showing which producttype they prefer. E.g. if Customer X makes 5 orders, 3x type A and 2x type B, I need the measure to return value A. I would also like to be able to calculate the 60% likelihood of them buying a product of type A (this can be a seperate measure). 

 

Because I'll need to do this for a lot of different product characteristics I'd prefer not having to make additional tables.

Anyway this is possible?

 

1 ACCEPTED SOLUTION
v-haibl-msft
Employee
Employee

@joerykeizer

 

Please try with following two measures.

Prefered_Product = 
CONCATENATEX (
    TOPN (
        1,
        SUMMARIZE (
            'Purchase Order',
            'Purchase Order'[Customer],
            'Purchase Order'[Product],
            "Number", COUNTROWS ( 'Purchase Order' )
        ),
        [Number]
    ),
    'Purchase Order'[Product], ", "
)
Likehood = 
VAR Prefered_Product =
    CONCATENATEX (
        TOPN (
            1,
            SUMMARIZE (
                'Purchase Order',
                'Purchase Order'[Customer],
                'Purchase Order'[Product],
                "Number", COUNTROWS ( 'Purchase Order' )
            ),
            [Number]
        ),
        'Purchase Order'[Product],
        ", "
    )
RETURN
    (
        DIVIDE (
            CALCULATE (
                COUNTROWS ( 'Purchase Order' ),
                FILTER ( 'Purchase Order', 'Purchase Order'[Product] = Prefered_Product )
            ),
            COUNTROWS ( 'Purchase Order' )
        )
    )

Measure for most recurring value_1.jpg

 

Best Regards,

Herbert

View solution in original post

19 REPLIES 19
joerykeizer
Helper II
Helper II

@v-haibl-msft

 

Got it! Thank's again. Learning the VAR functionality was especially helpful.

joerykeizer
Helper II
Helper II

@v-haibl-msft Awesome solution, thank you very much.

 

A follow up question if I you don't mind. Now I run into a 'problem' when there are two product types with the same value. It shows the preference as "A, B" but there is no real product type "A, B" so the likelyhood is empty.

 

Is it possible to show only 1 product type based on another column (date). So if it's 50/50 it would pick the most recent one. Or if this is easier: keep the "A, B" but return the percentage of both individual types? 

 

@joerykeizer

 

Please try to change the formula of Prefered_Product with nested TOPN as below.

Prefered_Product = 
CONCATENATEX (
    TOPN (
        1,
        TOPN (
            1,
            SUMMARIZE (
                'Purchase Order',
                'Purchase Order'[Customer],
                'Purchase Order'[Product],
                'Purchase Order'[Date],
                "Number", CALCULATE (
                    COUNTROWS ( 'Purchase Order' ),
                    ALLEXCEPT (
                        'Purchase Order',
                        'Purchase Order'[Customer],
                        'Purchase Order'[Product]
                    )
                )
            ),
            [Number]
        ),
        'Purchase Order'[Date]
    ),
    'Purchase Order'[Product]
)

Measure for most recurring value_1.jpg

 

Best Regards,

Herbert

v-haibl-msft
Employee
Employee

@joerykeizer

 

Please try with following two measures.

Prefered_Product = 
CONCATENATEX (
    TOPN (
        1,
        SUMMARIZE (
            'Purchase Order',
            'Purchase Order'[Customer],
            'Purchase Order'[Product],
            "Number", COUNTROWS ( 'Purchase Order' )
        ),
        [Number]
    ),
    'Purchase Order'[Product], ", "
)
Likehood = 
VAR Prefered_Product =
    CONCATENATEX (
        TOPN (
            1,
            SUMMARIZE (
                'Purchase Order',
                'Purchase Order'[Customer],
                'Purchase Order'[Product],
                "Number", COUNTROWS ( 'Purchase Order' )
            ),
            [Number]
        ),
        'Purchase Order'[Product],
        ", "
    )
RETURN
    (
        DIVIDE (
            CALCULATE (
                COUNTROWS ( 'Purchase Order' ),
                FILTER ( 'Purchase Order', 'Purchase Order'[Product] = Prefered_Product )
            ),
            COUNTROWS ( 'Purchase Order' )
        )
    )

Measure for most recurring value_1.jpg

 

Best Regards,

Herbert

Anonymous
Not applicable

@v-haibl-msft

Hi, one question, what does 'NUmber" stands for? I am trying to appl your dax function, but i don´t know waht to put i "Number" because if I put "Number", it appear in Read, as well as the ", ".

I want to do the same but to show the average marital status of my employees.

My Data is located in "Data", the employees in "Name", and the martial Status in "Civil Status".

 

The function I am doing is: 

Recurrent Civil Status = CONCATENATEX(TOPN(1,SUMMARIZE(Data,Data[Name],Data[Civil status]),COUNTROWS(Data),1),Data[Civil status],1)

 

thank you very much!

@Anonymous

 

Hi, please share sample data and expected result and maybe we can help in a better way

 

Regards




Lima - Peru
Anonymous
Not applicable

Hola! Creo que hablas español, te explico. Necesito que aparezca lo siguiente:

Cual es el Estado Civil más repedito, casado, soltero, etc. 

Lo que estoy armando es un reporte del trabajador promedio, y quiero colocar la edad promedio, tiempo de servicio promedio, etc. y uno de los campos es el estado civil promedio de mi población. 

Lo mismo quiero hacer del género, distrito donde vive, cantidad de hijos, etc.

 

NameMarital Status
ALEGRIA SOTOCASADO (A)
ABAD LLACSAHUANCASADO (A)
ANCORI BUSTAMANTSOLTERO (A)
BOJORQUEZ VACASADO (A)
BRUNA ALVSOLTERO (A)
ABANTO GIL GRESOLTERO (A)
CASTILLO DIAZCASADO (A)
ABANTO PAREDES DIASOLTERO (A)
CHANCOS ALLCA ANTHSOLTERO (A)
ABANTO VERTIZ LISOLTERO (A)
CHILO REA LILIASOLTERO (A)
GARCIA FERNANDEZ FREDCASADO (A)
GOMEZ VELARDCASADO (A)
ACERO ROMERO DANSOLTERO (A)
ACEVEDO GEREDA MIGUSOLTERO (A)
ACOSTA BARREDA JUNISOLTERO (A)
GUEVARA CORRALES JORGSOLTERO (A)
GUZMAN HERRERA ENRICASADO (A)
HERRERA ZENTENO SANDCASADO (A)
ORTEGA RSOLTERO (A)
PRIETO LANDSOLTERO (A)
QUIROZ RIVERO JCASADO (A)
AGUILAR MEDICONVIVIENTE
AGUILAR MEJICO ELISOLTERO (A)
AGUILAR ROSOLTERO (A)
AGUILAR SALINACASADO (A)
RIVAS PACHECO VICTSOLTERO (A)
RUIZ DIAZSOLTERO (A)

@Anonymous

 

The easiest way i think is this:

 

A table Visual and this fields and apply a TOPN

 

Status.png




Lima - Peru

@Anonymous

 

If you want a Dax Formula you can use this:

 

Measure =
CONCATENATEX (
    TOPN (
        1,
        SUMMARIZECOLUMNS (
            Table1[Marital Status],
            "Contar", CALCULATE ( COUNT ( Table1[Marital Status] ) )
        ),
        [Contar]
    ),
    Table1[Marital Status],
    "."
)



Lima - Peru
Anonymous
Not applicable

And what does Contar stands for? beacuse it appears in red. i put between [] and it appear the following:marital.png

 

 

 

In this case contar is the name of the colum created to store the count of each marital status. This column after is call to use to elaborate the Top1. The first is with " and the second is with []



Lima - Peru
Anonymous
Not applicable

I have to create this column then, in my excel? or in Powwer BI? what should I put?

thanks a lot!! @Vvelarde

@Anonymous

 

Is not necessary created a new column the dax formula create temporaly.

 

Look this is the dax for your data:

 

topMarStatus.png

 

Maybe you need to replace ; by , and Table1 by your table name.

 

 




Lima - Peru
joerykeizer
Helper II
Helper II

Thank you for your responses but I don't think the solution is there. The problem is that I don't want to show all product types but only return the one that occurs the most. The result should be 1 row per customer. 

 

So not:

Customer X - Product type A - 3x - 60%

Customer X - Product type B - 2x - 40%

 

But rather:

Customer X - Type A - 60%

 

I guess I could use RankX to rank by Customer/ProductType and only show Rank=1, but given my experiences with RankX so far it get's really slow with large amounts of data, so I prefer not to use it in this case. Is there something else?

If Possible, Send me an email to  -- ptelearningworld@gmail.com with your data and requirements.

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.
BhaveshPatel
Community Champion
Community Champion

 

Hi there,

 

For your question 1:

 

You can use CALCULATE  for counting only Prouduct A or Product B

 

TOTAL PRODUCTS:=COUNTROWS(PRODUCTS)

PRODUCT A:=CALCULATE([TOTAL PRODUCTS), FILTER(PRODUCTS, PRODUCTS[PRODUCTNAME]="PRODUCT A")

Similarly

 Change the last part of the DAX Measure and use PRODUCT B.

 

For Calculating the chances of Buying Product B with Product A,

 

Please refer to the post here:

http://www.daxpatterns.com/basket-analysis/

 

This will help to answer the Part B of your Question.

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.
Greg_Deckler
Super User
Super User

For the other measure, you would use a formula like:

 

Percent = COUNT([Order])/CALCULATE(COUNT([Order]),ALL(Orders))

And then put that measure in a table along with your "Product Type"


@ 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...
Greg_Deckler
Super User
Super User

I would suggets using RANKX: https://msdn.microsoft.com/en-us/library/gg492185.aspx

 


@ 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...
Habib
Responsive Resident
Responsive Resident

You should use RANK function based on Product Type Count and group by Customer and Product Type. This will give you a summarized table having information for each customer and then you can adjust your ranking to get likelihood of purchase

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.