Forum Discussion

vinzenz_t_t's avatar
vinzenz_t_t
Regular Visitor
8 years ago

Average Dimension Values for Distinct Count

Hey Power BI Community!

 

My name is Vinzenz and I have a Question about Power BI.

 

Let me model the problem real quick:

  

Customer IDSales Owner IDDateCalendar Week

Revenue

Last 30 Days

Customer Health
11234501.01.20171                                         0 k€0
21234501.01.20171                                      50 k€1
11234502.01.20172                                         0 k€0
21234502.01.20172                                      50 k€1
11234503.01.20172                                         0 k€0
21234503.01.20172                                      50 k€1
11234504.01.20172                                         0 k€0
21234504.01.20172                                      50 k€1
11234505.01.20172                                      50 k€1
21234505.01.20172                                      50 k€1
11234506.01.20172                                      50 k€1
21234506.01.20172                                    100 k€2
11234507.01.20172                                      50 k€1
21234507.01.20172                                    100 k€2
11234508.01.20172                                      50 k€1
21234508.01.20172                                    100 k€2
11234509.01.20173                                      10 k€1
21234509.01.20173                                      50 k€1
11234510.01.20173                                    100 k€2
21234510.01.20173                                      50 k€1
11234511.01.20173                                    100 k€2
21234511.01.20173                                      50 k€1
11234512.01.20173                                    100 k€2
21234512.01.20173                                      50 k€1
11234513.01.20173                                    150 k€3
21234513.01.20173                                         0 k€0
11234514.01.20173                                    150 k€3
21234514.01.20173                                         0 k€0
11234515.01.20173                                    150 k€3
21234515.01.20173                                         0 k€0
11234516.01.20174                                    150 k€3
21234516.01.20174                                         0 k€0
11234517.01.20174                                    100 k€2
21234517.01.20174                                         0 k€0
11234518.01.20174                                    100 k€2
21234518.01.20174                                         0 k€0
11234519.01.20174                                    100 k€2

 

For every date and every customer we calculate the revenue of the last 30 days in SQL.

Depending on the amount of revenue made in the last 30 days a customer health status is calculated, also in SQL.

Let's say in this example...

exactly 0€ revenue means health status 0,

anything above 0€ means status 1,

anything above 50k€ is status 2 and

anything above 100k€ is status 3.

 

So we basically created a dimension out of the customer's revenue numbers. This is all done in SQL (stored as a table) and we now put this into Power BI Desktop.

 

In Power BI the customer health is used as a dimension on a stacked area chart.

Axis: Date (Day)

Legend: Customer Health (0,1,2,3)

Values: DISTINCTCOUNT(customer_id)

This all works fine and gives us a nice graph that every member of upper mangement loves.

 

The problem: As soon as you switch The Axis from anything less granular than date(day), e.g. date(month) or sales owner you run into problems with dublets.

 

Why?

 

Power BI seems to count the distinct customer IDs for every date and every health-group. Meaning: When a customer is in more than one group for a given month, his ID is counted in both health groups.

This makes sense from a technical view, but obscours ours numbers - they should not amount to a higher customer count than we actually have.

 

So I imagen the solution could be a grouped average based on the vizualization.

 

I know that there's AVERAGEA which averages out dimensions. This is already pretty nice but it does it a global scale. The Average should be grouped by the customer ID. So when a customer is in health states 0,1 and 2 in one month - but mostly in health state 1 - The dimension should be aggregated to 1. Hence we avoid double counting. I also read about SUMMARIZECOLUMN

 

Problem: It doesn't seem to work.

 

Aggregated Health= GROUPBY('Table','Table[customer_id], "newdimension",AVERAGEA('Table'[customer_health]))

/!\ Function 'GROUPBY' scalar expressions have to be Aggregation functions over CurrentGroup(). The expression of each Aggregation has to be either a constant or directly reference the columns in CurrentGroup().

So I guess the aggregation in the expression has to accept CurrentGroup() as an argument. AVERAGEA does not seem to do this.

 

Aggregated Health= SUMMARIZECOLUMNS('Table'[customer_id],"newdimension",AVERAGEA('Table'[customer_health))

/!\ The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

 

I do not quite get what it's trying to tell me.

 

This could also be used for any other rolling status, like signed customers, customers having booked certain extra options/features for a given amount of time, and so on.

 

So the question is: Can I handle this operation in Power BI? Do I have to change my data modeling prior in SQL?

 

I hope I could make the problem understandable. If you need more explanation on the topic just let me know.

 

Best

 

Vinzenz

1 Reply

  • v-cherch-msft's avatar
    v-cherch-msft
    Microsoft Employee

    Hi vinzenz_t_t

     

     

    You can get the 'count' column which grouped by Customer ID for each health status with SUMMARIZE Function.

     

    So you may try to create a measure as below to get the mostly health status for each customer with TOPN Function.

    Top =
    VAR a =
        SUMMARIZE (
            Table1,
            Table1[Customer ID],
            Table1[Customer Health],
            "count", COUNTROWS ( Table1 )
        )
    RETURN
        CALCULATE ( MAX ( Table1[Customer Health] ), TOPN ( 1, a, [count], DESC ) )

     

    Regards,

    Cherie