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
PowerBrian
Regular Visitor

Trying to aggregate values from 2 different fields in the same table

I have a fact table that contains a column named 'start product' and a separate column named 'end_product'.  I want to return a separate table with 3 columns: 'product_name', count(start_product), count('end_product').  This seems like it should be really simple, but I can't figure it out.

1 ACCEPTED SOLUTION

Hi, @PowerBrian 

 

Please try the following methods.

Table:

results_table = 
DISTINCT(UNION(VALUES(fact_table[start_product]),VALUES(fact_table[end_product])))

Manually change one of the following names.

vzhangti_0-1656484021184.png

Column:

start_product_count = 
CALCULATE (
    COUNT ( fact_table[start_product] ),
    FILTER ( 'fact_table', [start_product] = EARLIER ( 'results_table'[product] ) )
) + 0
end_product_count = 
CALCULATE (
    COUNT ( fact_table[end_product] ),
    FILTER ( 'fact_table', [end_product] = EARLIER ( 'results_table'[product] ) )
) + 0

vzhangti_1-1656484139342.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

4 REPLIES 4
Seanan
Solution Supplier
Solution Supplier

Hi @PowerBrian 

A similar post here should be able to help you. when it comes to counting the start and end product you can use a simple measure to get the counts:

Create 2 of these measures, 1 for start_product and 1 for end_product.

 

CountSales = COUNT(SalesTeam[Sales])

 

 If you need any extra help please let me know.

Thanks for the response.  I think the thing that is confusing me is that the values are in the same table.  As an example, my fact table would contain the following:

 

fact_table

start_productend_product
AA
AC
BE
CC
DF
AD
CA

 

The results that I would expect in my new table would be the following:

 

results_table

productstart_product_countend_product_count
A32
B10

C

22
D11
E01
F01

 

 

I want to be able to pull all of the product types from the start_product column and all of the products from the end_product column and aggregate them into a single list.  After the list is created, I would like to have the total number of instances for each in separate columns.

Hi, @PowerBrian 

 

Please try the following methods.

Table:

results_table = 
DISTINCT(UNION(VALUES(fact_table[start_product]),VALUES(fact_table[end_product])))

Manually change one of the following names.

vzhangti_0-1656484021184.png

Column:

start_product_count = 
CALCULATE (
    COUNT ( fact_table[start_product] ),
    FILTER ( 'fact_table', [start_product] = EARLIER ( 'results_table'[product] ) )
) + 0
end_product_count = 
CALCULATE (
    COUNT ( fact_table[end_product] ),
    FILTER ( 'fact_table', [end_product] = EARLIER ( 'results_table'[product] ) )
) + 0

vzhangti_1-1656484139342.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Hi @PowerBrian 

Would it be possible for you to provide the PBIX file?

Please make sure there is no sensitive data in the file.

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.