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
soldstatic
Resolver I
Resolver I

Measure in a Measure

OK I know this is stupid I'm just hitting a wall and my brain is fried. I must be searching for the wrong thing. I have two tables such as:

 

Event Table

EventMetric ComponentDate/TimeYear-Mon
1101/1/2018 5:30AM2018-1
2421/3/2018 5:30AM2018-1
354312/1/2018 5:30AM2018-2
42492/1/2018 6:30AM2018-2

 

 

Customer Count table:

Year-MonCustomer Count
2018-1600
2018-2650

 

Which currently I use excel to develop something along the lines of this to analyze the 'Metric Total' which is measured as Metric Component / Customer Count:

 

Year-MonMetric ComponentCustomer CountMetric Total
2018-152600       0.09
2018-25680650       8.74
Total:5732625       9.17

 

In PowerBI I have my two tables, the Year-Mon column is a calculated column. Now the problem is that the customer count needs to be averaged when it is aggregated. So before drilling down, I want Power BI to show me the "Total" row as in the resultant table above. Then as I drill down it would split into the monthly view, etc. In practice this will actually be an annual view for the past several years, but the user can drill into the current month.

 

So for the customer table, I have a measure defined as:

Avg Customers = average('Customers'[Customers])

 

Then for the 'result', I created a measure within the event table:

METRIC = SUM(‘Data’[Metric Component]) / SUM('Customers'[Avg Customers])

 

This throws an error because it doesn't like a measure in a measure apparently. I've also tried:

METRIC = Sum('Data'[Metric Component]) / calculate( sum('Customers'[Avg Customers]),AllSelected())

 

But I'm just hitting a brick wall. What in the world am I doing wrong?

1 ACCEPTED SOLUTION

@soldstatic

 

For the tricky part you can use this measure:

 

Measure =
AVERAGEX (
    SUMMARIZE (
        Table1;
        Table1[Year];
        Table1[Month];
        "CustomSum"; SUM ( Table1[Customers] )
    );
    [CustomSum]
)

Now you need to combine the measure with the other simple measure to evaluate the context and show what you want.

 

Regards

 

Victor

 




Lima - Peru

View solution in original post

4 REPLIES 4
Vvelarde
Community Champion
Community Champion

@soldstatic

 

Hi, try with:

 

MetricTotal =
SUM ( Data[Metric Component] ) / [Avg Customers]

Regards

 

Victor




Lima - Peru

Unfortunately that doesn't work because it averages across the whole set of customers.

 

I realize I may have screwed up in defining the problem because I know my issue is with how I'm handling the customers. Tried to keep it simple for the forum and I think I bit myself in the foot. Here's a more accurate description of the customer table:

 

TerritoryCustomersYearMonthYearMon
A37,381.00201712201712
B47,416.00201712201712
C10,106.00201712201712
D109,685.00201712201712
E64,144.00201712201712
F9,551.00201712201712
G152,264.00201712201712
H61,934.00201712201712
I20,968.00201712201712
J10,536.00201712201712
K14,323.00201712201712
L7,801.00201712201712
M101,184.00201712201712
N30,221.00201712201712
O17,931.00201712201712
P15,918.00201712201712
Q83,562.00201712201712
R49,529.00201712201712
S2,844.00201712201712
T21,332.00201712201712
A37,452.002018120181
B47,483.002018120181
C10,108.002018120181
D109,898.002018120181
E64,600.002018120181
F9,548.002018120181
G152,249.002018120181
H61,999.002018120181
I20,983.002018120181
J10,530.002018120181
K14,327.002018120181
L7,804.002018120181
M105,975.002018120181
N30,184.002018120181
O18,001.002018120181
P15,908.002018120181
Q83,549.002018120181
R49,557.002018120181
S2,835.002018120181
T21,348.002018120181
A10,512.002018320183
B14,583.002018320183
C7,795.002018320183
D105,777.002018320183
E30,154.002018320183
F18,058.002018320183
G15,895.002018320183
H83,514.002018320183
I49,475.002018320183
J2,826.002018320183
K21,353.002018320183
L37,498.002018320183
M47,551.002018320183
N10,104.002018320183
O109,784.002018320183
P64,638.002018320183
Q9,586.002018320183
R152,341.002018320183
S62,076.002018320183
T21,019.0020183

20183

 

I have a calculated column that also concatenates the territory on each table so that I have a YearMonTerritory column such as 20182T which is the 'key' to tell each row in the event table which row in the customer table goes with it. There's 1 record in the customer table and many in the event table.

 

So if I'm drilled in on a single territory in a single month in a single year, say territory T in March of 2018, I want the denominate of my Metric function to be 21,019. But if I am looking at territory T in 2018, I want it to be the average of Territory T for 2018 which with the table above would be 21,183.5 . Then if I am looking at all years it would be 21,233 . 

 

The tricky part is if I'm looking at a total or a subset of the territories, it needs to be the average of the sum of the territories over the time frame. So if I'm looking at all territories in March 2018, I want to use 874,539. If I'm looking at all of 2018 I want the average of the months showing in this table, or: 874,338 (for March) + 874,539 (For January) / 2 = 874,438.5 (for 2018). Then if I'm looking at all time, I would be using 872,502.3 . 

 

So the definition you mentioned is the first syntax I tried, but it uses 43,726.9 for March 2018.

@soldstatic

 

For the tricky part you can use this measure:

 

Measure =
AVERAGEX (
    SUMMARIZE (
        Table1;
        Table1[Year];
        Table1[Month];
        "CustomSum"; SUM ( Table1[Customers] )
    );
    [CustomSum]
)

Now you need to combine the measure with the other simple measure to evaluate the context and show what you want.

 

Regards

 

Victor

 




Lima - Peru

THANK YOU THANK YOU THANK YOU! That works like a charm. Beautiful. I never would've come up with that. I will have to learn more about this summarize funcitonality! Beautiful. Thanks again!!!

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.