Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
RobertoMonzon
Frequent Visitor

How to calculate and graph the recurrence of purchased products?

I am working on power BI and I would like to know the recurrence in which companies acquire items or services.
Most of the posts I have seen are about the frequency of products purchased, that is, the number of products purchased in a given amount of time.
But I want to know every time a product is purchased, I hope that with the columns I add you can tell me how to do it, the truth is it is something I have never done. Below I leave more details of my table

I have a column called 'DESC_CC' containing the names of several companies, and another column called 'DESCRIPTION_ART_SER' with the names of items or services the companies acquire. Additionally, there's a column named 'APPROVED_DATE' indicating the approval date. If the 'NO_SIC' column is empty, it means the item/service was not approved. Moreover, there's a 'CANCELLED' column; if it contains a value, it signifies that the item/service was approved but subsequently canceled. If it has no value, it means it was not canceled.

Could you advise on setting up a recurrence for this scenario?

 

IDDESCRIPTION_ART_SERNO_SICApproved dateCANCELLED
1000242ART1   
1000245ART210002425/29/2021 22:17 
1000246ART3   
1000250ART1   
1000251ART110002465/31/2021 11:42 
1000252ART310002475/31/2021 11:56 
1000253ART210002485/31/2021 12:07Y
1000254ART310002485/31/2021 12:07Y
1000255ART110002495/31/2021 12:15 
1 ACCEPTED SOLUTION
v-jianpeng-msft
Community Support
Community Support

@Greg_Deckler , thanks for your concern about this case. I tried to create a sample data myself based on the user's requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:

Hi, @RobertoMonzon 

Have you solved the current problem? Based on your description, if you want to calculate the recurrence of purchased products, you can create two calculated columns as follows:

Approved = IF(ISBLANK([NO_SIC]), "No", "Yes")
Cancelleda = IF(ISBLANK([CANCELLED]), "No", "Yes")

vjianpengmsft_0-1713755141538.png

Then create a measure using the following DAX expression:

recurrence of purchased products =
COUNTAX (
    FILTER (
        'ECOM_PURCHASE_ORDER_DETAIL',
        'ECOM_PURCHASE_ORDER_DETAIL'[Approved] = "Yes"
            && 'ECOM_PURCHASE_ORDER_DETAIL'[Cancelleda] = "No"
    ),
    'ECOM_PURCHASE_ORDER_DETAIL'[DESCRIPTION_ART_SER]
)

Put this measure in the table visual:

vjianpengmsft_1-1713755287159.png

If your situation doesn't allow you to create a calculated column, you can use a measure expression similar to the following:

MEASURE =
VAR _table =
    SUMMARIZE (
        ECOM_PURCHASE_ORDER_DETAIL,
        ECOM_PURCHASE_ORDER_DETAIL[ID],
        'ECOM_PURCHASE_ORDER_DETAIL'[DESCRIPTION_ART_SER],
        'ECOM_PURCHASE_ORDER_DETAIL'[NO_SIC],
        ECOM_PURCHASE_ORDER_DETAIL[APPROVED_DATE],
        ECOM_PURCHASE_ORDER_DETAIL[CANCELLED],
        "Approve", IF ( ISBLANK ( 'ECOM_PURCHASE_ORDER_DETAIL'[APPROVED_DATE] ), "No", "Yes" ),
        "cancell", IF ( ISBLANK ( 'ECOM_PURCHASE_ORDER_DETAIL'[CANCELLED] ), "No", "Yes" )
    )
VAR _count =
    COUNTAX (
        FILTER ( _table, [Approve] = "Yes" && [cancell] = "No" ),
        'ECOM_PURCHASE_ORDER_DETAIL'[DESCRIPTION_ART_SER]
    )
RETURN
    _count

Place this measure in the table visual:

vjianpengmsft_2-1713755456485.png

I've provided the PBIX file used this time below.

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-jianpeng-msft
Community Support
Community Support

@Greg_Deckler , thanks for your concern about this case. I tried to create a sample data myself based on the user's requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:

Hi, @RobertoMonzon 

Have you solved the current problem? Based on your description, if you want to calculate the recurrence of purchased products, you can create two calculated columns as follows:

Approved = IF(ISBLANK([NO_SIC]), "No", "Yes")
Cancelleda = IF(ISBLANK([CANCELLED]), "No", "Yes")

vjianpengmsft_0-1713755141538.png

Then create a measure using the following DAX expression:

recurrence of purchased products =
COUNTAX (
    FILTER (
        'ECOM_PURCHASE_ORDER_DETAIL',
        'ECOM_PURCHASE_ORDER_DETAIL'[Approved] = "Yes"
            && 'ECOM_PURCHASE_ORDER_DETAIL'[Cancelleda] = "No"
    ),
    'ECOM_PURCHASE_ORDER_DETAIL'[DESCRIPTION_ART_SER]
)

Put this measure in the table visual:

vjianpengmsft_1-1713755287159.png

If your situation doesn't allow you to create a calculated column, you can use a measure expression similar to the following:

MEASURE =
VAR _table =
    SUMMARIZE (
        ECOM_PURCHASE_ORDER_DETAIL,
        ECOM_PURCHASE_ORDER_DETAIL[ID],
        'ECOM_PURCHASE_ORDER_DETAIL'[DESCRIPTION_ART_SER],
        'ECOM_PURCHASE_ORDER_DETAIL'[NO_SIC],
        ECOM_PURCHASE_ORDER_DETAIL[APPROVED_DATE],
        ECOM_PURCHASE_ORDER_DETAIL[CANCELLED],
        "Approve", IF ( ISBLANK ( 'ECOM_PURCHASE_ORDER_DETAIL'[APPROVED_DATE] ), "No", "Yes" ),
        "cancell", IF ( ISBLANK ( 'ECOM_PURCHASE_ORDER_DETAIL'[CANCELLED] ), "No", "Yes" )
    )
VAR _count =
    COUNTAX (
        FILTER ( _table, [Approve] = "Yes" && [cancell] = "No" ),
        'ECOM_PURCHASE_ORDER_DETAIL'[DESCRIPTION_ART_SER]
    )
RETURN
    _count

Place this measure in the table visual:

vjianpengmsft_2-1713755456485.png

I've provided the PBIX file used this time below.

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@RobertoMonzon Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


Follow on LinkedIn
@ 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...

Hello

I just re edit the question.

I hope you can help me

I wrote this DAX code for a measure:

 

PromedioIntervaloCompra =
AVERAGEX(
    ADDCOLUMNS(
        SUMMARIZE(
            ECOM_PURCHASE_ORDER_DETAIL,
            ECOM_PURCHASE_ORDER_DETAIL[DESCRIPSION_ART_SER],
            "FechaAprobacion", MAX(ECOM_PURCHASE_ORDER_DETAIL[APPROVED_DATE])
        ),
        "Intervalo",
        VAR FechaActual = [FechaAprobacion]
        VAR FechaAnterior =
            CALCULATE(
                MAX(ECOM_PURCHASE_ORDER_DETAIL[APPROVED_DATE]),
                FILTER(
                    ECOM_PURCHASE_ORDER_DETAIL,
                    ECOM_PURCHASE_ORDER_DETAIL[DESCRIPSION_ART_SER] = EARLIER(ECOM_PURCHASE_ORDER_DETAIL[DESCRIPSION_ART_SER])
                        && ECOM_PURCHASE_ORDER_DETAIL[APPROVED_DATE] < FechaActual
                )
            )
        RETURN
            IF(ISBLANK(FechaAnterior), BLANK(), DATEDIFF(FechaAnterior, FechaActual, DAY))
    ),
    [Intervalo]
)

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.