Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Count of combinations of values (measures) in a table (summarizing by multiple values?)

Hey there.
I have a table visualizing the number of different channels held by an employee. I have to count how many times each combination and number of channels appears.
Thus, instead of full names, I have to somehow summarize this data and get the number of full names for each combination (see the second screenshot).
Also, these counters are measures that take into the account start and end dates of the employees, so that the data can be filtered dynamically by date. That's why a calculated column won't probably be a solution.


Here's how my data looks like:
resource_allocation table:

allocation_code (PK)FullNamestart_dateend_dateEmails CallsSocial
1employee103/03/202008/11/2020111
2employee201/01/2019  2 
............   


sdr_channels table:

channel_code (PK)allocation_code (FK)sdr_channel
11Emails
21Calls
31Social
42Calls
.........

 

Note: 'Emails', 'Calls' and 'Social' in the resource_allocation table are calculated columns. I use the following formula:

1. Emails = CALCULATE ( MAX(resource_allocation[allocation_code]), FILTER(sdr_channels, sdr_channels[sdr_channel]="Emails" && resource_allocation[allocation_code]=sdr_channels[allocation_code]))
2. Calls = CALCULATE ( MAX(resource_allocation[allocation_code]), FILTER(sdr_channels, sdr_channels[sdr_channel]="Calls" && resource_allocation[allocation_code]=sdr_channels[allocation_code]))
3.  Social = CALCULATE ( MAX(resource_allocation[allocation_code]), FILTER(sdr_channels, sdr_channels[sdr_channel]="Social" && resource_allocation[allocation_code]=sdr_channels[allocation_code]))


The measures-counters for the table visual are:

Email counter = CALCULATE(CALCULATE(COUNT(resource_allocation[Email]),FILTER(resource_allocation, resource_allocation[Allocated (HR)]=1),ALLEXCEPT(resource_allocation,resource_allocation[employee_code])))
Calls counter = CALCULATE(CALCULATE(COUNT(resource_allocation[Calls]),FILTER(resource_allocation, resource_allocation[Allocated (HR)]=1),ALLEXCEPT(resource_allocation,resource_allocation[employee_code])))
Social counter = CALCULATE(CALCULATE(COUNT(resource_allocation[Email and Web]),FILTER(resource_allocation, resource_allocation[Allocated (HR)]=1),ALLEXCEPT(resource_allocation,resource_allocation[employee_code])))

Where 
Allocated (HR) =
VAR max_Selected_Date =
IF(HASONEVALUE(Rolling_Calendar[Year]), MAX(Rolling_Calendar[Calendar]), TODAY())
VAR min_Selected_Date =
IF(HASONEVALUE(Rolling_Calendar[Year]), MIN(Rolling_Calendar[Calendar]), TODAY())
RETURN
CALCULATE(
SWITCH(
TRUE(),
FIRSTNONBLANK ( resource_allocation[start_date], 1 ) <= max_Selected_Date &&
FIRSTNONBLANK( resource_allocation[end_date], 1 ) >= min_Selected_Date,
1,
FIRSTNONBLANK ( resource_allocation[start_date], 1 ) <= max_Selected_Date &&
MAX(resource_allocation[end_date])=BLANK(),1,
0
))


Tables' relationships:

The result I want to achieve:

3 Replies

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

    Hi Anonymous ,

     

    Try this measure:

    Measure =
    CALCULATE (
        COUNT ( 'Table'[Full Name] ),
        FILTER (
            ALL ( 'Table' ),
            COUNTROWS (
                FILTER (
                    'Table',
                    'Table'[Calls Counter] = EARLIER ( 'Table'[Calls Counter] )
                        && EARLIER ( 'Table'[Email Counter] ) = 'Table'[Email Counter]
                        && 'Table'[Social Counter] = EARLIER ( 'Table'[Social Counter] )
                )
            )
        )
    )

     

     

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

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for your answer @V-lianl-msft .
      However, I think I can't use EARLIER with a measure (while my counters are measures). The part

      EARLIER ( 'Table'[Calls Counter] )

      is underlined red and it says "Parameter is not the correct type".

      Also, I can't edit this post properly for some reason, so I'll provide the additional info here...

      Here's how my data looks like:
      resource_allocation table:

      allocation_code (PK)FullNamestart_dateend_dateEmails CallsSocial
      1employee103/03/202008/11/2020111
      2employee201/01/2019 2
      ............


      sdr_channels table:

      channel_code (PK)allocation_code (FK)sdr_channel
      11Emails
      21Calls
      31Social
      42Calls
      .........



      Emails, Calls and Social in resource_allocation table are calculated columns, which look like this:

      Calls = IF(CALCULATE ( MAX(resource_allocation[allocation_code]), FILTER(sdr_channels, sdr_channels[sdr_channel]="Calls" && resource_allocation[allocation_code]=sdr_channels[allocation_code]))<>BLANK(),"C")

      The counter-measures look the following way:
      Calls counter = CALCULATE(CALCULATE(COUNT(resource_allocation[Calls]),FILTER(resource_allocation, resource_allocation[Allocated (HR)]=1),ALLEXCEPT(resource_allocation,resource_allocation[employee_code])))

      Where the Allocated measure is:
      Allocated (HR) =
      VAR max_Selected_Date =
      IF(HASONEVALUE(Rolling_Calendar[Year]), MAX(Rolling_Calendar[Calendar]), TODAY())
      VAR min_Selected_Date =
      IF(HASONEVALUE(Rolling_Calendar[Year]), MIN(Rolling_Calendar[Calendar]), TODAY())
      RETURN
      CALCULATE(
      SWITCH(
      TRUE(),
      FIRSTNONBLANK ( resource_allocation[start_date], 1 ) <= max_Selected_Date &&
      FIRSTNONBLANK( resource_allocation[end_date], 1 ) >= min_Selected_Date,
      1,
      FIRSTNONBLANK ( resource_allocation[start_date], 1 ) <= max_Selected_Date &&
      MAX(resource_allocation[end_date])=BLANK(),1,
      0
      ))