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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Calculate using filter

i have two tables 

 

First table has a date where citations were issued.

Second table has a date where officer was on a certain schedule.

 

The tables are joined by a unique ibm # 

 

i am trying to filter the data to show what shift the officer wrote the tickets on. I can get total citations written by the officer but if that officer works on a different shift it also produces the total for that shift as a total of the officer

ibmoffense_datecitation_number
jj22001/01/2022

1

jj22001/01/2022

2

jj22001/02/2022

5

aa42001/01/2022

3

aa42001/01/20224
aa42001/02/2022

6

 

ibmshiftshift start date
jj220a shift01/01/2022
jj220a shift01/02/2022
aa420b shift01/01/2022
aa420t shift01/02/2022
1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Create a calculated column on the Citation table

Shift = 
var offenseDate = Citations[Offense date]
return SELECTCOLUMNS( TOPN( 1, 
   FILTER( RELATEDTABLE( Shifts ), Shifts[Start date] <= offenseDate ),
   Shifts[Start date], DESC ),
   "@shift", Shifts[Shift]
)

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

Create a calculated column on the Citation table

Shift = 
var offenseDate = Citations[Offense date]
return SELECTCOLUMNS( TOPN( 1, 
   FILTER( RELATEDTABLE( Shifts ), Shifts[Start date] <= offenseDate ),
   Shifts[Start date], DESC ),
   "@shift", Shifts[Shift]
)
Anonymous
Not applicable

Thank you that works 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.