Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Sum against count group

Hi,

I've a fact table of sales data where I have customerKey , saleAmount and date in each record.

customerKey may repeat for sale transactions in a period.

Now I want to calculate sum of saleAmount against count of customers divided into groups.

for example,

Count of Customer1 in sale table =3

Count of Customer2 in sale table = 5

Count of Customer3 in sale table = 8

Count of Customer4 in sale table= 4

Count of Customer5 in sale table = 2

 

count groups are 1-5, 6-10, 11-15

I need total sum of saleAmount that is calculated on the count of customer falling in above groups.

I've tried multiple solution but sum against count groups can't be achieved. Help will be highly appreciated.

Thanks

  • Hi Anonymous ,

     

    Try to create two columns like below:

    count_customer = CALCULATE(COUNT('Table'[date]),ALLEXCEPT('Table','Table'[customerKey]))
    groups = SWITCH(TRUE(),
                'Table'[count_customer]>=1&&'Table'[count_customer]<=5,"1-5",
                'Table'[count_customer]>=6&&'Table'[count_customer]<=10,"6-10",
                ">10")

    Sample .pbix

     

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

4 Replies

  • Anonymous add a new column in customer table, it is similar to ABC analysis

     

    Count in Sales Table = 
    CALCULATE ( COUNTROWS ( SalesTable ), ALLEXCEPT ( Customer, Customer[CustomerKey] ) )

     

    Now in a table visual, use this new column (don't; summarize it since it is a number) and put the sale amount from the sales table, and you will get the result.

     

    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.

    • Anonymous's avatar
      Anonymous
      Not applicable

      parry2kThank you for your response.

      I'm getting this error

      and if it is corrected ,how will we be calculating the sum of saleAmount against the grouping of customer counts.

  • Anonymous it will work, but not sure why you are getting this error. Can you change Countrows to COUNT ( FactTable[CustomerKey] ) 

  • V-lianl-msft's avatar
    V-lianl-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

     

    Try to create two columns like below:

    count_customer = CALCULATE(COUNT('Table'[date]),ALLEXCEPT('Table','Table'[customerKey]))
    groups = SWITCH(TRUE(),
                'Table'[count_customer]>=1&&'Table'[count_customer]<=5,"1-5",
                'Table'[count_customer]>=6&&'Table'[count_customer]<=10,"6-10",
                ">10")

    Sample .pbix

     

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