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

Filter by two relationship

Hi,

 

I'm having some troubles trying to filter by two relationships at the same time. I would like to filter a table with two date using a relationship to another date.

 

How can I count how many records do I have in a table where date1 and date2 are between my Calendar[date] filter??

I tried like that but got some errors:

 

 

Total = 
CALCULATE (
    COUNT ( PERIOD[Date1] ); 
    USERELATIONSHIP ( 'Calendar'[Date]; PERIOD[Date1] ) &&
    USERELATIONSHIP ( 'Calendar'[Date]; PERIOD[Date2] )     
)

 

1 ACCEPTED SOLUTION

Hi

As for your example, try this measure to see if it helps

Measure =
CALCULATE (
    COUNT ( PERIOD[Date1] ),
    FILTER (
        ALLEXCEPT ( PERIOD, PERIOD[type] ),
        ( [Date1] <= MAX ( 'Calendar'[Date] ) )
            && ( [Date1] >= MIN ( 'Calendar'[Date] ) )
            && ( [Date2] <= MAX ( 'Calendar'[Date] ) )
            && ( [Date2] >= MIN ( 'Calendar'[Date] ) )
    )
)

 

Best Regards

Maggie

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @mdelasheras

 

Try this measure instead

records =
CALCULATE (
    COUNT ( PERIOD[Date1] ),
    FILTER (
        ALL ( PERIOD ),
        ( [Date1] <= MAX ( 'Calendar'[Date] ) )
            && ( [Date1] >= MIN ( 'Calendar'[Date] ) )
            && ( [Date2] <= MAX ( 'Calendar'[Date] ) )
            && ( [Date2] >= MIN ( 'Calendar'[Date] ) )
    )
)

7.png

 

Best Regards

Maggie

 

Thanks @v-juanli-msft,

 

This measure works as intended except other filters are not being applied now.
I would like to show this measure in a column chart with a shared axis and also apply some visual filters.  Now it's displaying the same value regardless what my other filters are. 

 

For example: PERIOD[country] is a shared axis and PERIOD[TYPE] is a visual filter.

 

How can I solve this problem?

 

Thanks again!

Hi

As for your example, try this measure to see if it helps

Measure =
CALCULATE (
    COUNT ( PERIOD[Date1] ),
    FILTER (
        ALLEXCEPT ( PERIOD, PERIOD[type] ),
        ( [Date1] <= MAX ( 'Calendar'[Date] ) )
            && ( [Date1] >= MIN ( 'Calendar'[Date] ) )
            && ( [Date2] <= MAX ( 'Calendar'[Date] ) )
            && ( [Date2] >= MIN ( 'Calendar'[Date] ) )
    )
)

 

Best Regards

Maggie

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.