Forum Discussion

PowerBrian's avatar
PowerBrian
Regular Visitor
4 years ago
Solved

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), co...
  • v-zhangti's avatar
    v-zhangti
    4 years ago

    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.

    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

    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.