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
padfootkk
Employee
Employee

How to apply different filters based on a time cutoff and apply it on same visuals

Hi everyone,

 

Now I'm facing a problem to apply different filters on the same visuals. Suppose I have two tables: Itemtable and Datetable, where Datetable contains date which includes month and year; An simple example of Itemtable is shown below. The two tables are connected by date.

Itemtable

ItemidAreaDate
1Adate
2Adate
3Bdate
4Bdate
5Bdate
6Cdate
7Ddate

 

Say I have a column chart that shows the count of items as y-axis, month as x-axis. Now I need to filter the data under different areas based on a time cutoff. For example, before 05/2019, I need the count of items under area path A, B; After 05/2019 (including 05/2019), I need the count of items under area path A, B, C. Different filters 

 

Is it possible to filter like what I want?

 
1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hi @padfootkk ,

 

Firstly, we create two spreate calculated table to select the area filter

 

AeraSelectAfterDate = DISTINCT('Table'[Area])

 

AeraSelectBeforDate = DISTINCT('Table'[Area])

 

11.PNG

 

Then we use the following measure as the value field of column chart:

 

Count of items =
IF (
    MAX ( 'Table'[Date] ) < DATE ( 2019, 5, 1 ),
    CALCULATE (
        COUNT ( 'Table'[Itemid] ),
        FILTER ( 'Table', [Area] IN FILTERS ( AeraSelectBeforDate[Area] ) )
    ),
    CALCULATE (
        COUNT ( 'Table'[Itemid] ),
        FILTER ( 'Table', [Area] IN FILTERS ( AeraSelectAfterDate[Area] ) )
    )
)

 

12.PNG

 


If it doesn't meet your requirement, Please show the exact expected result based on the Tables that you have shared.

 


BTW, pbix as attached.

 

Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Dong Li
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

3 REPLIES 3
v-lid-msft
Community Support
Community Support

Hi @padfootkk ,

 

Firstly, we create two spreate calculated table to select the area filter

 

AeraSelectAfterDate = DISTINCT('Table'[Area])

 

AeraSelectBeforDate = DISTINCT('Table'[Area])

 

11.PNG

 

Then we use the following measure as the value field of column chart:

 

Count of items =
IF (
    MAX ( 'Table'[Date] ) < DATE ( 2019, 5, 1 ),
    CALCULATE (
        COUNT ( 'Table'[Itemid] ),
        FILTER ( 'Table', [Area] IN FILTERS ( AeraSelectBeforDate[Area] ) )
    ),
    CALCULATE (
        COUNT ( 'Table'[Itemid] ),
        FILTER ( 'Table', [Area] IN FILTERS ( AeraSelectAfterDate[Area] ) )
    )
)

 

12.PNG

 


If it doesn't meet your requirement, Please show the exact expected result based on the Tables that you have shared.

 


BTW, pbix as attached.

 

Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you so much! This is exactly what I want 🙂

amitchandak
Super User
Super User

Try. in case of date is not coming from slicer

calculate(count(itemtable[item]),datetable[date]<date(2019,05,31))

calculate(count(itemtable[item]),datetable[date]>=date(2019,05,31))

 

Date coming from slicer

 

measure1 =
var _max_date = maxx(datetable,datetable[date])
return 
calculate(count(itemtable[item]),datetable[date]<_max_date))

measure2 =
var _max_date = maxx(datetable,datetable[date])
return 
calculate(count(itemtable[item]),datetable[date]>=_max_date)

 

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

 

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.