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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Farnaz_Raj98
Frequent Visitor

Findin maximum Count of records by date and IDs

Hi everyone, I'm new in power BI and I want to  achieve Table 3 but I don't know how?

I have 2 tables with data samples like below, in "Host" Table there are host's infos, in "Order" table there are orders that users bought from hosts, I want to know the maximum order count of a host is on which day of week?

 

Table: Host

IDName
1Jack
2Lili
3Hana
4Steve

 

Table:Orders

OrderIDHostIDPriceDateName
10012000000Saturday
2002100000Sunday
30011250000Saturday
4003205000Wedensday
5004200000Saturday
6001100000Monday
7003300000

Wedensday

 

 

Result

HostNameMaximumOrderCountDateName
Jack2Saturday
Lili1Sunday
Hana2Wedensday
Steve1Saturday
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Farnaz_Raj98 ,

Here are the steps you can follow:

1. Create calculated column.

Orders Table:

Countgroup1 =
COUNTX(
    FILTER(ALL(Orders),
    'Orders'[HostID]=EARLIER('Orders'[HostID])&&'Orders'[DateName]=EARLIER('Orders'[DateName]))
,
[HostID])
Countgroup2 =
MAXX(
    FILTER(ALL(Orders),
    'Orders'[HostID]=EARLIER('Orders'[HostID])),[Countgroup1])

vyangliumsft_0-1657458953984.png

Host Table:

MaximumOrderCount =
CALCULATE(
    MAX('Orders'[Countgroup2]),FILTER(ALL(Orders),
'Orders'[HostID]='Host'[ID]))
DateName =
CALCULATE(
    MAX('Orders'[DateName]),
    FILTER(ALL(Orders),
    'Orders'[HostID]='Host'[ID]&&
    'Orders'[Countgroup2]='Host'[MaximumOrderCount]))

vyangliumsft_1-1657458953985.png

2. Create calculated table.

Table3 =
SUMMARIZE(
    'Host',
    'Host'[Name],'Host'[MaximumOrderCount],'Host'[DateName])

3. Result:

vyangliumsft_2-1657458953986.png

 

If you need pbix, please click here.

 

Best Regards,

Liu Yang

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

8 REPLIES 8
Anonymous
Not applicable

Hi  @Farnaz_Raj98 ,

Here are the steps you can follow:

1. Create calculated column.

Orders Table:

Countgroup1 =
COUNTX(
    FILTER(ALL(Orders),
    'Orders'[HostID]=EARLIER('Orders'[HostID])&&'Orders'[DateName]=EARLIER('Orders'[DateName]))
,
[HostID])
Countgroup2 =
MAXX(
    FILTER(ALL(Orders),
    'Orders'[HostID]=EARLIER('Orders'[HostID])),[Countgroup1])

vyangliumsft_0-1657458953984.png

Host Table:

MaximumOrderCount =
CALCULATE(
    MAX('Orders'[Countgroup2]),FILTER(ALL(Orders),
'Orders'[HostID]='Host'[ID]))
DateName =
CALCULATE(
    MAX('Orders'[DateName]),
    FILTER(ALL(Orders),
    'Orders'[HostID]='Host'[ID]&&
    'Orders'[Countgroup2]='Host'[MaximumOrderCount]))

vyangliumsft_1-1657458953985.png

2. Create calculated table.

Table3 =
SUMMARIZE(
    'Host',
    'Host'[Name],'Host'[MaximumOrderCount],'Host'[DateName])

3. Result:

vyangliumsft_2-1657458953986.png

 

If you need pbix, please click here.

 

Best Regards,

Liu Yang

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

Thanks alot @Anonymous 
It works 🙂


Farnaz_Raj98
Frequent Visitor

Unfortunately it doesn't work john, it returns name of hosts with the same days and same Orders like below image

 

 

tamerj1
Super User
Super User

Hi @Farnaz_Raj98 
Please use

1.png

 

 

1.png

Maximum Order Count = 
MAXX (
    ADDCOLUMNS (
        VALUES ( Orders[DateName] ),
        "@Coun", CALCULATE ( COUNTROWS ( Orders ) )
    ),
    [@Coun]
)
DateName = 
VAR MaxCount = [Maximum Order Count]
VAR FilteredDateNames =
    FILTER (
        ADDCOLUMNS (
            VALUES ( Orders[DateName] ),
            "@Coun", CALCULATE ( COUNTROWS ( Orders ) )
        ),
        [@Coun] = MaxCount
    )
RETURN
    MAXX ( FilteredDateNames, Orders[DateName] )

 

 

 

Hey tamerj
my data model is like folliowing image which host is a table that obtained from experience table and hasn't directly relation with orders.

Farnaz_Raj98_1-1657347214844.png

so after the solution you suggested, the result came out with name of hosts but with repeated Date name and order count


Farnaz_Raj98_2-1657347596610.png

 

@Farnaz_Raj98 
which columns are involved in the relationships? Why do you have to use two way relationships?

 Orders(ExperienceID) and Experience(ID) have relation with the column in parenthesis and Host(HostID) and Experience(HostID),too. 

I used Two way relationships because I thought may be it affects on the result but it didn't and i forgot to change it into one way 

johnt75
Super User
Super User

You can create a couple of measures like

Max Order Count Day = 
var summaryTable = ADDCOLUMNS( VALUES(Orders[DateName]), "@num orders", CALCULATE( COUNTROWS( Orders)))
return CONCATENATEX( TOPN(1, summaryTable, [@num orders]), [DateName], ", ")

 and

Max Order Count = 
var summaryTable = ADDCOLUMNS( VALUES(Orders[DateName]), "@num orders", CALCULATE( COUNTROWS( Orders)))
return MAXX(summaryTable, [@num orders])

In the event that there are multiple days with the same number of orders, the Max Order Count Day measure will return a comma separated list of all the tied days

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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