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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
bjackson202
Regular Visitor

Modify count of customers per product to be based on dimension table attributes

Hello all,

 

I would like to change this calculated column definition to reference customer & product definitions found in dimProduct & dimCustomer tables:

Go from this:

// Distinct Count of Customer Key's per Product Key

CALCULATE(
DISTINCTCOUNT(factInvoices[CustomerKey]),
filter(factInvoices,factInvoices[ProductKey]=EARLIER(factInvoices[ProductKey]))
)

 

to this:

 

// Distinct Count of Customer Parents's per ProductParent

CALCULATE(
DISTINCTCOUNT(dimCustomer[CustomerParent]),
filter(factInvoices,dimProduct[ProductParent]=EARLIER(dimProduct[ProductParent]))

)

 

How can I force the calculated column expression to use row syntax for a related product & customer dimensions? 

 

Thank you!!!!

1 ACCEPTED SOLUTION

Thank you @Anonymous !

 

I ended up finding a post here that helped me out: https://www.daxpatterns.com/related-distinct-count/

 

The earlier() functionality was giving me issues with the dimension table attributes, so I changed the distinct count to a measure named [# Customers]: 

# Customers =
VAR CustsFromInvoices =
    SUMMARIZE ( FILTER(factInvoices,factInvoices[CurrentorBase]="Current"), dimCustomer[CustomerParent])
VAR Result =
    SUMX ( CustsFromInvoices, 1 )      -- optimization for COUNTROWS ( CustsFromInvoices )
RETURN
    Result

 

Then called that measure in a calculated column here: 

# Customer Parents per Product Parent =
VAR numCustPerProd =
    CALCULATE(
        [# Customers],                                              
        ALLEXCEPT(factInvoices,                                             
            dimProduct[ProductParent]
        )            
    )    
 
This got me my desired result, thank you for your time & help, and apologies for the lack of sample data & context!

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @bjackson202 ,

 

You can try to use RELATED() function.

Please try:

CALCULATE(
    DISTINCTCOUNT(dimCustomer[CustomerParent]),
    FILTER(
        factInvoices,
        RELATED(dimProduct[ProductParent]) = EARLIER(RELATED(dimProduct[ProductParent]))
    )
)
CALCULATE(
    DISTINCTCOUNT(dimCustomer[CustomerParent]),
    FILTER(
        factInvoices,
        factInvoices[ProductKey] = EARLIER(dimProduct[ProductKey])
            && factInvoices[CustomerKey] = RELATED(dimCustomer[CustomerKey])
    )
)

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Thank you @Anonymous !

 

I ended up finding a post here that helped me out: https://www.daxpatterns.com/related-distinct-count/

 

The earlier() functionality was giving me issues with the dimension table attributes, so I changed the distinct count to a measure named [# Customers]: 

# Customers =
VAR CustsFromInvoices =
    SUMMARIZE ( FILTER(factInvoices,factInvoices[CurrentorBase]="Current"), dimCustomer[CustomerParent])
VAR Result =
    SUMX ( CustsFromInvoices, 1 )      -- optimization for COUNTROWS ( CustsFromInvoices )
RETURN
    Result

 

Then called that measure in a calculated column here: 

# Customer Parents per Product Parent =
VAR numCustPerProd =
    CALCULATE(
        [# Customers],                                              
        ALLEXCEPT(factInvoices,                                             
            dimProduct[ProductParent]
        )            
    )    
 
This got me my desired result, thank you for your time & help, and apologies for the lack of sample data & context!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.