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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Summarize IDs with only one type of transaction

Goal: A field that returns the number customers who only have return transactions, a distinct count of Unique_IDs that have only one transaction_type and where that transaction_type=B.

 

Based on the definition, I think the calculation(s) need to first determine the IDs that have only one transaction type. Of those IDs, determine which have transaction_type=B, and then return the distinct count of remaining IDs. I’m having troubling stringing these steps together to produce the correct population of IDs. Do I need to create a relationship between the summarize table and the transaction table..? Or am I missing a function, or applying them in an order that changes that incorrectly alters the filter context?

 

This summarize correctly counts transaction types for each ID:

Customers Grouped by Transaction_Type =

SUMMARIZE(

    'TRANSACTION',

    'TRANSACTION'[Unique_ID],

    "Grouped by ID Returns",

    DISTINCTCOUNT('TRANSACTION'[Transaction_Type])

)

 

This field calc produces the count of customers with returns, but does not correctly filter out customers that have returns and purchases.

TEST Returns Only Customers=

    CALCULATE(

        DISTINCTCOUNT('TRANSACTION'[Unique_ID]),

        FILTER(

VALUES (‘Customers Grouped by Transaction_Type’[Unique_ID]),

[Grouped by ID Returns]=1
),

FILTER(

'TRANSACTION',

[Transaction_type]=“B”

)
)

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

You may refer to the measure below.

Measure =
COUNTROWS (
    FILTER (
        VALUES ( 'TRANSACTION'[Unique_ID] ),
        CALCULATE ( SELECTEDVALUE ( 'TRANSACTION'[Transaction_Type] ) = "B" )
    )
)
Community Support Team _ Sam Zha
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

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

You may refer to the measure below.

Measure =
COUNTROWS (
    FILTER (
        VALUES ( 'TRANSACTION'[Unique_ID] ),
        CALCULATE ( SELECTEDVALUE ( 'TRANSACTION'[Transaction_Type] ) = "B" )
    )
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Power BI automatically marked the solution as correct. While it may work for someone, it will not work for this case. The suggested syntax incorrectly assumes that each Unique ID corresponds to a single row. However, the data in this case is at the level of Transaction ID, which is more granular than the Unique ID. Since each Unique ID is associated with multiple Transaction IDs, it is not sufficient to use COUNTROWS and it will produce a count that is too high. 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.