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
bkr
Helper I
Helper I

Filter based on minimum of a subset of data

Hi folks,

 

I'm struggling with a summarytable in which I'd like to filter by year first and then by by a minimum of another table.

 

Say this is the starting Table1 (much simplified, of course):

YearSalesTopic
201851
2018103
201962
201983
2019114

 

Now I want to create a Summarytable:
Summarytable =
SUMMARIZE('Table1',

  "FilteredSales"; CALCULATE(
    SUM('Table1'[Sales]),
    FILTER('Table1'; 'Table1'[Year] = 2019),
    FILTER('Table1'; 'Table1'[Topic] = MIN('Table1'[Topic]))
  )

)

 

Of course, this returns a table with a single cell but that's for demonstration purpose only.
I would have expected this filters by year first, leaving the values for 2019 only and then give me the sales for the entry with the smallest number in Topic, hence return "6".

However, it returns nothing because there is no entry for 2019 that also has the smallest number in Topic.

 

How can I achieve a nested filter that filters by one column first and then applies the MIN function only on the result of that first filter?

 

N.B.: "Year" could also be any other column, so date functions won't help.

2 ACCEPTED SOLUTIONS
JarroVGIT
Resident Rockstar
Resident Rockstar

Try this:

Summarytable = 
VAR tmpTable = FILTER('Table1', 'Table1'[Year] = 2019)
RETURN
SUMMARIZE(tmpTable,
  "FilteredSales", 
    SUMX(FILTER(tmpTable, [Topic] = MINX(tmpTable, [Topic])), [Sales])   
)

Tested it myself 🙂 

image.png

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





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

Proud to be a Super User!




View solution in original post

I found it myself based on your suggestion:

 

The trick is to do a

NewTable = 
SUMMARIZE('Table1',
"FilteredSales", CALCULATE(
SUM('Table1'[Sales]),
FILTER('Table1'[Topic] = MINX(FILTER('Table1'; [Year] = 2019), [Topic])))

 

This might decrease performance but that way I still can further work with the original table to create other columns

View solution in original post

4 REPLIES 4
JarroVGIT
Resident Rockstar
Resident Rockstar

Try this:

Summarytable = 
VAR tmpTable = FILTER('Table1', 'Table1'[Year] = 2019)
RETURN
SUMMARIZE(tmpTable,
  "FilteredSales", 
    SUMX(FILTER(tmpTable, [Topic] = MINX(tmpTable, [Topic])), [Sales])   
)

Tested it myself 🙂 

image.png

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





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

Proud to be a Super User!




Hi Djerro,

 

thanks, this in principle works. However, it seems as i narrowed down the problem too much. In another column of my summarytable I need to do some work with the 2018 data which is not possible because all the 2018 data is lost in the tmptable. Is there a way to nest the filters only for a specific column?

JarroVGIT
Resident Rockstar
Resident Rockstar

Please provide your expected end result as a table and I will adjust the solution accordingly. Thanks!




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

Proud to be a Super User!




I found it myself based on your suggestion:

 

The trick is to do a

NewTable = 
SUMMARIZE('Table1',
"FilteredSales", CALCULATE(
SUM('Table1'[Sales]),
FILTER('Table1'[Topic] = MINX(FILTER('Table1'; [Year] = 2019), [Topic])))

 

This might decrease performance but that way I still can further work with the original table to create other columns

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.

Top Solution Authors