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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

count all related records in a month

Hi

 

I have contacts with related orders (N:1)

 

Orders have a field "created on" (datefield)

 

I need to count and display all contacts that have more than one order created per month

 

How can I fulfill this?

 

Thnaks in advance for the help!

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

Hi @Anonymous ,

 

Here is my original data table:
c23.PNG

 

Create a ‘Count_order’ column in ‘Orders’ table, the column is used to count the orders for every contact per month:

 

 

Count_order = 
CALCULATE(
    COUNT(Orders[Create on]),
    FILTER(
        Orders,
        Orders[Create on].[Month] = EARLIER(Orders[Create on].[Month]) 
        &&
        Orders[Create on].[Year] = EARLIER(Orders[Create on].[Year]) 
        &&
        Orders[Contacts_ID] = EARLIER(Orders[Contacts_ID])
    )
)

 

 

Then, create a ‘if over 1’ column in ‘Orders’ table, the column is used to judge if the order number is over 1:

 

 

if over 1 = 
IF(
    Orders[Count_order] >1,
    TRUE(),
    FALSE()
)

 

 

c24.PNG

At last, create a ‘if over 1’ column in ‘Contacts’ table:

 

 

if over 1 = 
LOOKUPVALUE(
    Orders[if over 1],
    Orders[Contacts_ID], Contacts[Contacts_ID],
    Orders[if over 1], TRUE()
    
)

 

 

c25.PNG

 

If you want to show the number of the contacts  who have more than 1 orders  per month, you can do like this:

 

 

Count_contact = 
CALCULATE(
    DISTINCTCOUNT(Orders[Contacts_ID]),
    FILTER(
        Orders,
        Orders[Count_order] >1
    )
) 

 

 

ca.PNG

 

Best Regards,
Lionel Chen

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

1 REPLY 1
v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

 

Here is my original data table:
c23.PNG

 

Create a ‘Count_order’ column in ‘Orders’ table, the column is used to count the orders for every contact per month:

 

 

Count_order = 
CALCULATE(
    COUNT(Orders[Create on]),
    FILTER(
        Orders,
        Orders[Create on].[Month] = EARLIER(Orders[Create on].[Month]) 
        &&
        Orders[Create on].[Year] = EARLIER(Orders[Create on].[Year]) 
        &&
        Orders[Contacts_ID] = EARLIER(Orders[Contacts_ID])
    )
)

 

 

Then, create a ‘if over 1’ column in ‘Orders’ table, the column is used to judge if the order number is over 1:

 

 

if over 1 = 
IF(
    Orders[Count_order] >1,
    TRUE(),
    FALSE()
)

 

 

c24.PNG

At last, create a ‘if over 1’ column in ‘Contacts’ table:

 

 

if over 1 = 
LOOKUPVALUE(
    Orders[if over 1],
    Orders[Contacts_ID], Contacts[Contacts_ID],
    Orders[if over 1], TRUE()
    
)

 

 

c25.PNG

 

If you want to show the number of the contacts  who have more than 1 orders  per month, you can do like this:

 

 

Count_contact = 
CALCULATE(
    DISTINCTCOUNT(Orders[Contacts_ID]),
    FILTER(
        Orders,
        Orders[Count_order] >1
    )
) 

 

 

ca.PNG

 

Best Regards,
Lionel Chen

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

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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