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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Jayshamone
Helper I
Helper I

DAX - Count number of Transactions with n Items

Hi,

 

I have a detailed data model and I would like to calculate how many transactions there are with n items per transaction.

In SQL this would look something like this:

 

 

select		numOfItems, count(*) as transactions
from (
	select		transaction_id, count (*) as numOfItems
	from		trans_articles
	group by	transaction_id
	) temp
group by	numOfItems

 

 

 

However I have no idea how a DAX-measure could look like that generates a result like this.

I've added a .pbix file with some demo data as well as a python-visualisation of the expected / desired result.

You can download it here.

 

Could someone help, please?

 

Thanks in advance

Justus

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

Hi , @Jayshamone 

According to your description, and thanks for your sample .pbix fike , you want to get the data the same as your sql.

Here are the steps you can refer to :
(1)We need to create a dimension table like your [numOfItem], we can click "New Table" and enter this:

Table = var _max_items =MAXX( SUMMARIZE('Tabelle1', 'Tabelle1'[transaction_id], "count" ,COUNT('Tabelle1'[item_position])) , [count])
return
GenerateSeries(1,_max_items)

And the table we do not create any relationship between the other tables.

 

(2)Then we can create two measures:

Measure = var _summrize_tranid = SUMMARIZE('Tabelle1', 'Tabelle1'[transaction_id], "count" ,COUNT('Tabelle1'[item_position]))
var _cur_item_count = MAX('Table'[Value])
var _count = COUNTROWS( FILTER(_summrize_tranid , [count] = _cur_item_count))
return
_count
Right Total = SUMX( VALUES('Table'[Value]) , [Measure])

(3)Then we can put the 'Table'[Value] and the [Right Total] on the table visual and we can meet your need:

vyueyunzhmsft_0-1673230847268.png

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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-yueyunzh-msft
Community Support
Community Support

Hi , @Jayshamone 

According to your description, and thanks for your sample .pbix fike , you want to get the data the same as your sql.

Here are the steps you can refer to :
(1)We need to create a dimension table like your [numOfItem], we can click "New Table" and enter this:

Table = var _max_items =MAXX( SUMMARIZE('Tabelle1', 'Tabelle1'[transaction_id], "count" ,COUNT('Tabelle1'[item_position])) , [count])
return
GenerateSeries(1,_max_items)

And the table we do not create any relationship between the other tables.

 

(2)Then we can create two measures:

Measure = var _summrize_tranid = SUMMARIZE('Tabelle1', 'Tabelle1'[transaction_id], "count" ,COUNT('Tabelle1'[item_position]))
var _cur_item_count = MAX('Table'[Value])
var _count = COUNTROWS( FILTER(_summrize_tranid , [count] = _cur_item_count))
return
_count
Right Total = SUMX( VALUES('Table'[Value]) , [Measure])

(3)Then we can put the 'Table'[Value] and the [Right Total] on the table visual and we can meet your need:

vyueyunzhmsft_0-1673230847268.png

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

Thank you for the transparent and easy to understand step-by-step solution

 

amitchandak
Super User
Super User

@Jayshamone , You have to create a measure first and then create a dynamic segmentation

 

cnt  = count(Table[Transaction ID])

 

Dynamic segmentation -Measure to Dimension conversion: https://youtu.be/gzY40NWJpWQ

 

When you need between range

Dynamic Segmentation Bucketing Binning
https://community.powerbi.com/t5/Quick-Measures-Gallery/Dynamic-Segmentation-Bucketing-Binning/m-p/1...


Dynamic Segmentation, Bucketing or Binning: https://youtu.be/CuczXPj0N-k

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors