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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
JimmyDQN
Helper I
Helper I

AverageIF - Based on one category, combined with another average

Hi all,

Our developer (small time company) is on vacation and since I am not able to do calculated columns myself as we use SSAS cube, I am hoping one of you can help me. 
The thing is - I have a Hierarchy in Table 1 containing Continent, Country and City. In Table 2, I have Person ID and Table 3, I have hours registered. 

I would like to do a measure (preferably a calculated column, but I am not able to do this, as I don't have access to the SQL server) where I am calculating the following: an Average based on City and an Average compared to the others in the same city. I would LOVE for it to be in the same table / visualization. Is this even doable without any developer having to create a new column for me?

 

See an example below

ContinentCountryCityPerson IDHours registeredAverageBasedonCityAverage compared to group in City
AsiaChinaGuangzhou76875,00%
AsiaChinaGuangzhou8108125,00%
EUGermanyBerlin23475,00%
EUGermanyBerlin454125,00%
EUSwedenStockholm655100,00%
NAUSANew York121811,11%
NAUSANew York341822,22%
NAUSANew York561833,33%
NAUSALA404040100,00%
NAUSANEw York106018333,33%




1 ACCEPTED SOLUTION

Hi @JimmyDQN,

 

Is it a Direct Query connection? I have updated the attachment. You can try it again.

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

15 REPLIES 15
v-jiascu-msft
Employee
Employee

Hi @JimmyDQN,

 

Can you share a dummy sample, please? The data and its structure are the critical parts to make a formula. For example, 

1. How did these data tables connect?

2. Which columns have duplicates?

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-jiascu-msft

 

Hi, 

 

I have an attachment above. Or do you mean the data model? 🙂

Hi @JimmyDQN,

 

Yes, it's the data model. You have at least three tables. I need to know the connections among them.

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Pic.PNG

 

@v-jiascu-msft would this help? 🙂

Hi @JimmyDQN,

 

The calculated column [AverageBasedonCity] is easy and it should be in the table 'geography'.

 

AverageBasedonCity =
CALCULATE (
    AVERAGE ( 'hours registered'[Hours] ),
    ALLEXCEPT ( 'geography', 'geography'[city] )
)

The other one could be in the table 'hours registered'. 

 

 

Average compared to group in City =
[hours] / RELATED ( 'geography'[AverageBasedonCity] )

If they aren't correct, please provide a dummy sample.

 

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-jiascu-msft Would it be possible to do this without calculated columns but only measures?

Hi @JimmyDQN,

 

Yes, I just follow your first post. It could be like below. If not, please share a sample.

 

AverageBasedonCity =
CALCULATE (
    AVERAGE ( 'hours registered'[Hours] ),
    ALLEXCEPT ( 'geography', 'geography'[city] ),
    ALL ( person )
)
Average compared to group in City =
SUM ( [hours] ) / [AverageBasedonCity]

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

It does not work unfortunatly, how do I attach a file?

Hi @JimmyDQN,

 

You can upload the file to a cloud drive like OneDrive, GoogleDrive then share the link here or send me a message through Messages. Please mask the sensitive parts first.

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-jiascu-msft https://drive.google.com/open?id=1pGmwarQb1xM9o0HeCj3T096vksUGuomO here is the link. 

 

I couldnt, for some reason, make a realtionship from Geography. I had to export some data, as it is on a SSAS cube.

Hi @JimmyDQN,

 

Please check out the demo in the attachment. There are solutions both of "calculated column" and "measure". 

Though I don't know why there are duplicates in the Geography table which is thought to be a dimension table, the solutions work.

BTW, we can create a many-to-many relationship now.

averageif

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I get an error trying to download this. But, I cannot make columns as I am on an SSAS cube. 

Hi @JimmyDQN,

 

Is it a Direct Query connection? I have updated the attachment. You can try it again.

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

 

sorry for the late reply. 

 

It is correct that I am using direct query. I will try to look at this tomorrow 🙂 

JimmyDQN
Helper I
Helper I

Anyone? 🙂

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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