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
dusiod
Regular Visitor

Aggregation and dynamic filter

Hello,  
I am trying to calculate aggregated data (by Level 1) which respond to slicer selections (on level 2) 

Specific Example:
Data

Level1Level2Level3Data
Azq1
Azzq2
Azzzr3
Azzzzr4
Bzq10
Bzzq20
Bzzzr30
Bzzzzr40

 


Aggregate Data: 

Option 1.  Create a table using GroupBy and join it using Level1 (in the relationship tab)

Table1_agg =
 
GROUPBY(
   Table1,
   Table1[Level1],
   "AggL1_Data",sumx(CURRENTGROUP(),Table1[Data])
)

 

Option 2. Use Filter wihtin Table1

AggL1_Filter = 
    Calculate(
    sum(Table1[Data]),
    FILTER(
        Table1,
        Table1[Level1]= EARLIER(Table1[Level1])
        )
)  

Result - aggregation WORKS

image.png

 

However filtering using the Level2 Slicer does NOT work. 
AggL1 still shows 10 and 100 where as I want to see 5 (for A) and 50 (for B)
image.png

 

Help would be greatly appreciated, I've been stuck on this for ages,

 

Thanks in advance,

dusiod

 

2 ACCEPTED SOLUTIONS
dusiod
Regular Visitor

Ok I think I've made this work using:

0Measure = 
CALCULATE(
    SUM(Table1[Data]),
    FILTER(ALLSELECTED(Table1),Table1[Level1]=MAX(Table1[Level1]))
)
 

But can anyone explain what MAX(Table1[level1]) is doing in the filter.... do not understand especially as MAX is supposed to ignore Booleans and Text, and in this case Level1 has string fields....

View solution in original post

v-yuezhe-msft
Employee
Employee

@dusiod,

Calculated columns will not respond to slicer selection, this is why your first DAX doesn't work with Level 2 filter. See this Power BI KB.

You eventually create a measure, which works correctly with level 2 filter. The max() function in the measure has similar effect as the EARLIER() function, it will check if your rows share same level1 value, and will result in your measure to sum data based on same level1.

Regards,
Lydia

Community Support Team _ Lydia Zhang
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

2 REPLIES 2
v-yuezhe-msft
Employee
Employee

@dusiod,

Calculated columns will not respond to slicer selection, this is why your first DAX doesn't work with Level 2 filter. See this Power BI KB.

You eventually create a measure, which works correctly with level 2 filter. The max() function in the measure has similar effect as the EARLIER() function, it will check if your rows share same level1 value, and will result in your measure to sum data based on same level1.

Regards,
Lydia

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

Ok I think I've made this work using:

0Measure = 
CALCULATE(
    SUM(Table1[Data]),
    FILTER(ALLSELECTED(Table1),Table1[Level1]=MAX(Table1[Level1]))
)
 

But can anyone explain what MAX(Table1[level1]) is doing in the filter.... do not understand especially as MAX is supposed to ignore Booleans and Text, and in this case Level1 has string fields....

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.