Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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:

tables relationship.png

The result I want to achieve:

Margaryta_0-1597260668681.png

3 REPLIES 3
V-lianl-msft
Community Support
Community 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] )
            )
        )
    )
)

V-lianl-msft_0-1597307499300.png

 

 

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
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
))

parry2k
Super User
Super User

@Anonymous your problem is not very clear. Read this post to get your answer quickly.

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.