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

Filtering a measure doesn't work in Aggregated Context

Hi,

 

I've created a Measure which calculates another measure with an applied filter, but the filtering is incorrect in an aggregated context. Any suggestions? Note that the nested measure definition (i.e. give me [Devices] for which X is true) is a requirement for this.

 

I'm trying to answer following:

Given a set of devices, each with a session count and whether the sessions were "Is Enabled".

Give me a number of devices for which 50% or more sessions were Enabled.

 

Measure in question:

[Enabled Devices: [Devices]] + Enabled] = CALCULATE( [Devices], FILTER(Table1, [Percentage of Enabled Sessions] >= 0.5))

 

 

But this gives me all [Devices] without the filter being applied. In the below input dataset, only one device out of two should pass the check, but the above measure returns 2:

image.png

Test input:

 

DeviceIs EnabledSessions
1TRUE3
1TRUE2
1FALSE1
1FALSE1
2TRUE1
2FALSE5

 

Measures:

Devices = CALCULATE( SUMX(SUMMARIZE(Table1,Table1[Device]),1), Table1[Device]>0)
 
Percentage of Enabled Sessions =
SUMX(SUMMARIZE( Table1,
Table1[Device],
"Number of Enabled Sessions", CALCULATE(SUM(Table1[Sessions]), Table1[Is Enabled] = true),
"Number of All Sessions", SUM(Table1[Sessions])),
DIVIDE([Number of Enabled Sessions], [Number of All Sessions]))
 
Over 0.5 Sessions being Enabled = IF([Percentage of Enabled Sessions] > 0.5, "Yes", "No")
 
Intermediate output:

 

 

image.png

 

 

Thanks!

 

 

 
1 ACCEPTED SOLUTION

I think I've found a solution using an inner join which gives 1 in the test sampleset. Thanks Kristjan76 for giving me a hint why it wasn't working.

[Enabled Devices: [Devices]] + Enabled 2] =
VAR tbl = ADDCOLUMNS(SUMMARIZE( Table1,
Table1[Device],
"Number of Enabled Sessions", CALCULATE(SUM(Table1[Sessions]), Table1[Is Enabled] = true),
"Number of All Sessions", SUM(Table1[Sessions])),

"Percentage of Enabled Sessions", DIVIDE([Number of Enabled Sessions], [Number of All Sessions]))
RETURN
CALCULATE([Devices], FILTER(NATURALINNERJOIN(tbl, Table1), [Percentage of Enabled Sessions] >= 0.5))

View solution in original post

4 REPLIES 4
Kristjan76
Responsive Resident
Responsive Resident

[Enabled Devices: [Devices]] + Enabled] = VAR tbl = ADDCOLUMNS( SUMMARIZE( Table1; Table1[Device]; "Number of Enabled Sessions"; CALCULATE(SUM(Table1[Sessions]); Table1[Is Enabled] = true); "Number of All Sessions"; SUM(Table1[Sessions]) ); "Enable";DIVIDE([Number of Enabled Sessions]; [Number of All Sessions]) ) RETURN COUNTROWS( FILTER( tbl; [Enable]>0,5 ) )

That gives the correct count, but is it possible to do this by calling a [Devices] measure within the parent measure and not calculate it in place? In other words, can I filter the table just to devices that pass the [Percentage of Enabled Sessions ] check and hand that off to the [Devices] measure to apply any further filters? So instead of doing the commented version from Kristjan76's solution, which gives 1, to the uncommented one, which gives 2,?

 

[Enabled Devices: [Devices]] + Enabled 2] =
VAR tbl = ADDCOLUMNS(SUMMARIZE( Table1,
Table1[Device],
"Number of Enabled Sessions", CALCULATE(SUM(Table1[Sessions]), Table1[Is Enabled] = true),
"Number of All Sessions", SUM(Table1[Sessions])),
"Percentage of Enabled Sessions", DIVIDE([Number of Enabled Sessions], [Number of All Sessions]))

RETURN

// COUNTROWS(FILTER(tbl, [Percentage of Enabled Sessions] >= 0.5))

CALCULATE( [Devices],
FILTER(tbl, [Percentage of Enabled Sessions] >= 0.5))

I think I've found a solution using an inner join which gives 1 in the test sampleset. Thanks Kristjan76 for giving me a hint why it wasn't working.

[Enabled Devices: [Devices]] + Enabled 2] =
VAR tbl = ADDCOLUMNS(SUMMARIZE( Table1,
Table1[Device],
"Number of Enabled Sessions", CALCULATE(SUM(Table1[Sessions]), Table1[Is Enabled] = true),
"Number of All Sessions", SUM(Table1[Sessions])),

"Percentage of Enabled Sessions", DIVIDE([Number of Enabled Sessions], [Number of All Sessions]))
RETURN
CALCULATE([Devices], FILTER(NATURALINNERJOIN(tbl, Table1), [Percentage of Enabled Sessions] >= 0.5))
Peter_
Resolver I
Resolver I

Is it maybe that the parent measure is not evaluating [Percentage of Enabled Sessions] at per device granularity? Is it possible to do so with nested measure?

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.