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

Nested Filters in Calculated column

Dear members hi.

 

I really need your help!

I have a calculated column where I am retrieving the max ID from another table based on specific parameters.

My code is as follows:

Calculate(Max('Table1'[ID]), Filter(

               Filter (

               Filter(

                  Table1[countryid]=table2[countryid]),

Table1[cityid]=table2[cityid]),

Table1[start date]<=table2[date] &&

Table1[end date]>table2[date] ),

Table1 [flag]=false)

)

I need a way either to optimize this calculated column or reproduce this code as measure .

Any ideas on how to do it??

Thank you very much in advance 🙂

1 ACCEPTED SOLUTION

Sorry to hear that. Here's a different variation to reduce the number of rows scaned.

 

MaxIDMeasure =
VAR MaxCountryID = MAX('table2'[countryid])
VAR MaxCityID = MAX('table2'[cityid])
VAR MaxDate = MAX('table2'[date])

RETURN
CALCULATE(
MAX('Table1'[ID]),
'Table1'[countryid] = MaxCountryID,
'Table1'[cityid] = MaxCityID,
'Table1'[start date] <= MaxDate,
'Table1'[end date] > MaxDate,
'Table1'[flag] = FALSE()
)

 





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

Proud to be a Super User!




View solution in original post

3 REPLIES 3
amustafa
Super User
Super User

Hi @Dimitris_Kats ,

 

You can try this as a measure:

 

MaxIDMeasure =
CALCULATE(
MAX('Table1'[ID]),
FILTER(
'Table1',
'Table1'[countryid] = MAX('table2'[countryid]) &&
'Table1'[cityid] = MAX('table2'[cityid]) &&
'Table1'[start date] <= MAX('table2'[date]) &&
'Table1'[end date] > MAX('table2'[date]) &&
'Table1'[flag] = FALSE()
)
)

 





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

Proud to be a Super User!




Hello @amustafa 

Thank you very much for replying to me.

I have already tried this measure. Unfortunately it's loading forever and fails 😞

Sorry to hear that. Here's a different variation to reduce the number of rows scaned.

 

MaxIDMeasure =
VAR MaxCountryID = MAX('table2'[countryid])
VAR MaxCityID = MAX('table2'[cityid])
VAR MaxDate = MAX('table2'[date])

RETURN
CALCULATE(
MAX('Table1'[ID]),
'Table1'[countryid] = MaxCountryID,
'Table1'[cityid] = MaxCityID,
'Table1'[start date] <= MaxDate,
'Table1'[end date] > MaxDate,
'Table1'[flag] = FALSE()
)

 





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

Proud to be a Super User!




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.