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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
saralyndsay
Frequent Visitor

Count Transactions Where Items are Only From One Category

I'm trying to figure out the best way to approach this request. 

 

We have sales transaction data at the sku level, with categories attached. We want to know how many transactions ONLY have items from one specific category on it, and then how many transactions have that category on it as well as others. 

 

Example Data:

Transaction NumberCategorySku
123Dog Food1
123Cat Food7
124Dog Food1
124Dog Food2
125Dog Food1
126Cat Food7
126Bird Food8
126Dog Food1

 

So if we were looking for how many transactions were ONLY for dog food, the measure would return a count of 2 (transactions 124 and 125). Transactions that contained dog food would return a count of 3 (transactions 124, 125 and 126)

 

Any help would be appreciated!!

1 ACCEPTED SOLUTION
v-xulin-mstf
Community Support
Community Support

Hi @saralyndsay,

 

You can create calculated table as:

Dog food only = 
var tab =
SUMMARIZE(
    'Table',
    'Table'[Category],
    'Table'[Transaction Number]
)
return
FILTER(
    tab,
    COUNTX(FILTER(tab,[Transaction Number] = EARLIER('Table'[Transaction Number])),[Transaction Number]) = 1 && 'Table'[Category]="Dog Food"
)

Here is the output:

vxulinmstf_0-1626168367096.png

The pbix is attached.

If you still have some question, please don't hesitate to let me known.‌‌

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

View solution in original post

7 REPLIES 7
v-xulin-mstf
Community Support
Community Support

Hi @saralyndsay,

 

You can create calculated table as:

Dog food only = 
var tab =
SUMMARIZE(
    'Table',
    'Table'[Category],
    'Table'[Transaction Number]
)
return
FILTER(
    tab,
    COUNTX(FILTER(tab,[Transaction Number] = EARLIER('Table'[Transaction Number])),[Transaction Number]) = 1 && 'Table'[Category]="Dog Food"
)

Here is the output:

vxulinmstf_0-1626168367096.png

The pbix is attached.

If you still have some question, please don't hesitate to let me known.‌‌

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

v-xulin-mstf
Community Support
Community Support

Hi @saralyndsay ,

 

You can try measure as:

Dog food only = 
var _TN=SELECTEDVALUE('Table'[Transaction Number])
var _tab=
SUMMARIZE('Table','Table'[Transaction Number],'Table'[Category],"tab",'Table'[Transaction Number]=_TN)
return 
IF(
    COUNTROWS(_tab)=1,
    1,
    0
)

Here is the output:

vxulinmstf_0-1625551145702.png

The pbix is attached.

 

If you still have some question, please don't hesitate to let me known.‌‌

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

@v-xulin-mstf Just trying to understand how that measure is looking at the Dog Food category. If I now wanted to look at Cat Food, how would the measure change? I don't see where the Dog Food category is indicated. 

 

aj1973
Community Champion
Community Champion

Hi @saralyndsay 

Is this good

aj1973_0-1625073902785.png

aj1973_1-1625073941434.png

 

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

@aj1973 That works for counting the transactions that have dogfood anywhere, but not those that have ONLY dogfood. There are two different calcuatlions I need. 

What ONLY dog food represent? where is that Category?

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

It is the dogfood category, but we want to know how many transactions only have that one category on it. Ie the customer did not purchase any other categories. In my example, there are only two transactions that have dog food as the only category purchased. So the measure would return 2

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.