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
yharfush
Frequent Visitor

Measures over groups

Hello,

 

I have a table with data regarding penetration of different media vehicles by city. I already have the first 4 columns shown below, and I want to calculate the last 3 columns:

 

VEHICLECITYPENETRATIONTOTAL_PEOPLE%PENETRATIONNATIONAL_PENETRATIONAFFINITY
A112025347%46%103%
A28223135%46%77%
A37119037%46%81%
A49412277%46%167%
B18011172%60%121%
B240041497%60%162%
B311335032%60%54%
B47624531%60%52%
C135037294%80%117%
C223431574%80%92%
C312316873%80%91%
C434545476%80%95%

 

The logic is as follows:

 

%PENETRATION = PENETRATION / TOTAL_PEOPLE (this is the penetration by city)

NATIONAL_PENETRATION = SUM(PENETRATION) / SUM(TOTAL_PEOPLE) for each vehicle (which is why the value gets repeated if we're refering to the same vehicle)

AFFINITY = %PENETRATION / NATIONAL_PENETRATION (it compares the penetration of one vehicle in one city, to the national penetration of that same vehicle)

 

I was able to calculate %PENETRATION and NATIONAL_PENETRATION using Measures, however when I try to calculate AFFINITY I'm not getting the result I want because I'm doing the average of NATIONAL_PENETRATION of all vehicles, and I don't know how to tell Power BI to do an average for each vehicle A, B and C. This is the formula I'm using:

 

AFFINITY =
DIVIDE(
[% PENETRATION],
AVERAGE('Table Name'[NATIONAL_PENETRATION])
)

I would appreciate any help or suggestions.

Best regards!

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @yharfush,

 

Create the following measures:

 

% Penetration = SUM(Affinaties[PENETRATION])/SUM(Affinaties[TOTAL_PEOPLE])

National penetration = CALCULATE( [% Penetration]; ALLEXCEPT(Affinaties;Affinaties[VEHICLE]))

affinity = [% Penetration]/Affinaties[National penetration]

This give the result below:

 

%penetration.png

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @yharfush,

 

Create the following measures:

 

% Penetration = SUM(Affinaties[PENETRATION])/SUM(Affinaties[TOTAL_PEOPLE])

National penetration = CALCULATE( [% Penetration]; ALLEXCEPT(Affinaties;Affinaties[VEHICLE]))

affinity = [% Penetration]/Affinaties[National penetration]

This give the result below:

 

%penetration.png

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you so much, @MFelix! It works perfectly with the example I provided.

 

However, I would like to ask you if there is a way to integrate a condition into the ALLEXCEPT part of the formula. In my real data, I have a binary column that I'm using to filter the rows of my table, this is to indicate if that record belongs to a market or not. Because of this, the numbers I get for NATIONAL_PENETRATION are incorrect, I assume it is summing all values instead of only the ones that belong to the market. Do you know if this is possible?

 

Thank you so much 🙂

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.