Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Date filter works on TextColumn1 but needs to consider DateColumn in another table

Table1:

member.id     date                               hours        
john22.2.2023 09:00:006
john3.5.2022 11:00:005
sue4.6.2019 08:30:0012
sue7.8.2021 09:00:003
sue12.3.2022 10:00:005

 

Table2

member.alias                 datestart                   dateend                       group            
john1.1.2022 08:00:001.8.2022 08:00:00group1
john2.8.2022 08:00:00 group2
sue1.6.2019 08:00:0014.3.2022 08:00:00group1

 

Table1 and Table2 have relationship: member.id to member.alias 

All date columns are type: datetime

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

I have a filter1 that uses: date, in Table1.

 When I select year 2019 I see: sue

 When I select year 2022 I see: sue and john

 When I select year 2023 I see: john

I have another filter (filter2) on the same page that uses: group, in Table2.

 When I select year 2019 I see: group1 in filter2

 When I select year 2022 I see: group1 and group2 in filter2

 When I select year 2023 I see: group1 and group2 in filter2

This is incorrect, I only want to see group2 for the year 2023.

But because John also has an older registration for group1, both groups appear in filter2.

 

So the scenario I want: When I select year in filter1 I want filter2 to only display groups for the selected year.

 

Can anyone assist?

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

Hi @Anonymous ,

 

Please try to apply this measure to the visual's filter:

Flag = 
var _a = ADDCOLUMNS('Table2',"Flag",IF(ISBLANK([dateend]),COUNTROWS(FILTER(SELECTCOLUMNS('Table1',"Date",[date]),[Date]>=[datestart])),COUNTROWS(FILTER(SELECTCOLUMNS('Table1',"Date",[date]),[Date]>=[datestart]&&[Date]<=[dateend]))))
return SUMX(_a,[Flag])

vjianbolimsft_0-1686639245086.png

Final output:

vjianbolimsft_1-1686639322496.png

Best Regards,

Jianbo 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

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try to apply this measure to the visual's filter:

Flag = 
var _a = ADDCOLUMNS('Table2',"Flag",IF(ISBLANK([dateend]),COUNTROWS(FILTER(SELECTCOLUMNS('Table1',"Date",[date]),[Date]>=[datestart])),COUNTROWS(FILTER(SELECTCOLUMNS('Table1',"Date",[date]),[Date]>=[datestart]&&[Date]<=[dateend]))))
return SUMX(_a,[Flag])

vjianbolimsft_0-1686639245086.png

Final output:

vjianbolimsft_1-1686639322496.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

NaveenGandhi
Super User
Super User

@Anonymous 

Unfortunately there is no standard solution that fits to all in this situation.

It depends on how your data is, If you can share you data or PBIX after removing sensitive information, That will be useful to take a look into it further.

If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!


NaveenGandhi
Super User
Super User

Hello @Anonymous 

The tables you have above will cause a many to many relationship. SInce "John" has both group 1 and group 2 in table 2, You will see group 1 and group 2 when you select him.

You should try to create a unique Primay key in table 2 that you can use in table 1.

Let me know if this helps!

If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!



Try to create the 


Anonymous
Not applicable

Thanks for the reply NaveenGandhi.

 

I can't see another relationship option between the two tables 😕

Do you have any other suggestion for me to tackle this problem?

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.