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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
PBI_newuser
Post Prodigy
Post Prodigy

Count the order number by Account

Hi, how to sum the number or orders per account?

If the number of order per account >5, then set it as 5.

 

I have created the below measures, but the sum = 6 which is incorrect.

Total Orders by Account = IF(CALCULATE(DISTINCTCOUNT(Data[Order]), 
GROUPBY(Data,Data[Account]))>5,5,CALCULATE(DISTINCTCOUNT(Data[Order]), GROUPBY(Data,Data[Account])))

 

Expected Outcome:

Account# of Order
A5
B3
C2
Total10

 

OrderAccount
O-123A
O-234B
O-345A
O-456A
O-567B
O-678C
O-789A
O-900A
O-1011C
O-1122A
O-1233B



1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @PBI_newuser 

Please check the below picture and the sample pbix file's link down below.

 

Picture4.png

 

Number of Orders Measure =
VAR newtable =
SUMMARIZE (
'Table',
'Table'[Account],
"@orderscountcondition", IF ( COUNTROWS ( 'Table' ) >= 5, 5, COUNTROWS ( 'Table' ) )
)
RETURN
SUMX ( newtable, [@orderscountcondition] )

 

https://www.dropbox.com/s/f1203rsgdmonu5y/newuser.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi, @PBI_newuser 

Please check the below picture and the sample pbix file's link down below.

 

Picture4.png

 

Number of Orders Measure =
VAR newtable =
SUMMARIZE (
'Table',
'Table'[Account],
"@orderscountcondition", IF ( COUNTROWS ( 'Table' ) >= 5, 5, COUNTROWS ( 'Table' ) )
)
RETURN
SUMX ( newtable, [@orderscountcondition] )

 

https://www.dropbox.com/s/f1203rsgdmonu5y/newuser.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi @Jihwan_Kim, I tried to modify your measure but it doesn't work. Sample here.

I changed the condition by replacing the "5" with a measure. Could you please help? Thanks.

Number of Orders Measure = 
VAR newtable =
SUMMARIZE (
'Table',
'Table'[Account],
"@orderscountcondition", IF ( COUNTROWS ( 'Table' ) >= [Max Orders Per Account], [Max Orders Per Account], COUNTROWS ( 'Table' ) )
)
RETURN
SUMX ( newtable, [@orderscountcondition] )
Can "Montdiff" calculate the month difference when users select Relatvie Date?
I noticed when I select Account=C, the Montdiff = 6 although i have selected "Last 12 months".
Monthdiff = CALCULATE(DATEDIFF(MIN('Table'[Date]),Max('Table'[Date]),MONTH)+1,ALLSELECTED('Table'))
 
Max Orders Per Account = 6/12 * [Monthdiff]

Hi, @PBI_newuser 

I am not 100% sure that I understand what you are looking for, but please try the below.

 

Number of Orders =
VAR maxordersperaccount = [Max Orders Per Account]
VAR newtable =
SUMMARIZE (
'Table',
'Table'[Account],
"@orderscountcondition",
IF (
COUNTROWS ( 'Table' ) >= maxordersperaccount,
maxordersperaccount,
COUNTROWS ( 'Table' )
)
)
RETURN
SUMX ( newtable, [@orderscountcondition] )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi @Jihwan_Kim , it works!! Thank you so much!! 😀

One more question, why when I select Account = B or C, the Penalty % in the card is different from the table? How to make the card to display the same % as the one display in the table? Sample here.

PBI_newuser_0-1623661332906.png

 

PBI_newuser_1-1623661354781.png

 

 

Hi, @PBI_newuser 

I do not understand the logic of other measures. And I do not know how your desired outcome looks like.

However, I just can guess it has something to do with ALLEXCEPT function in your measure.

Please check the link below whether it is what you are looking for.

 

https://www.dropbox.com/s/2wf5fvbzhybccqw/newuser_Max%20Order%20%281%29.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.