Forum Discussion

geotech's avatar
geotech
Frequent Visitor
5 years ago
Solved

Sum column by group based on another column containing a value

Hello All,

 

I have the data table below where I would like to sum the revenue by job name if the item number "2222" is present.

Job NameItem NumberRevenue
Project 11111 $        50,000
Project 12222 $        40,000
Project 21111 $        60,000
Project 22222 $        55,000
Project 23333 $        10,000
Project 31111 $        30,000

 

The result should be $215,000 (all rows except the last for this simplified example).

 

I've tried using the measure below, however it only sums the revenue for the item number "2222" and not the total job revenue.

 

Job Revenue by 2222 =
    CALCULATE (
    SUM('Table Name'[Revenue]),
    ALLEXCEPT('Table Name','Table Name'[Job Name]),
    FILTER('Table Name', FIND ( "2222", 'Table Name'[Item Number],, 0 ) <> 0 )
)

 

I understand why the code above does not work, but I cannot seem to figure out how to manipulate this in the way that I need for the measure to work properly. 

 

I would greatly appreciate any assistance in tuning this up, thank you.

  • geotech I will this improved measure

     

    Sum Job 2 = 
    VAR __jobs = CALCULATETABLE ( VALUES ( Job[Job Name] ), Job[Item Number] = "2222"  )
    RETURN
    CALCULATE ( SUM ( Job[Revenue] ), __jobs  ) 

     

    Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

4 Replies

  • geotech try this measure

     

    Sum Job = 
    CALCULATE ( 
        SUM ( Job[Revenue] ),
        FILTER ( 
            SUMMARIZE ( 
                FILTER ( Job, Job[Item Number] = "2222" ), 
                Job[Job Name], "@Count", COUNTROWS ( Job ) 
            ), 
            [@Count] > 0 
        )
    )

     

     

    Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

  • geotech I will this improved measure

     

    Sum Job 2 = 
    VAR __jobs = CALCULATETABLE ( VALUES ( Job[Job Name] ), Job[Item Number] = "2222"  )
    RETURN
    CALCULATE ( SUM ( Job[Revenue] ), __jobs  ) 

     

    Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • geotech's avatar
      geotech
      Frequent Visitor

      parry2k , thank you so much for the quick response! This is working very well.

       

      Thank you, again

  • geotech glad I could help and it worked.

     

    Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.