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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Blouey
Regular Visitor

Tagging required data by several conditions

Hi all,

The sample data set is shown below for the problem.

 

I'm trying filter out a data set so that for a given TimePeriod, each Name has only their most recent ModifiedDate retained. I would also need for duplicates of the same Name, TimePeriod and ModifiedDate to be filtered out (eg. first two rows for Dan).

 

Any advice appreciated.
Many thanks!

 

NameTimePeriodModifiedDate
Ash30/01/2022 23:5930/01/2022 11:10
Ash30/01/2022 23:5930/01/2022 11:10
Bob30/01/2022 23:5931/01/2022 4:50
Bob30/01/2022 23:5928/01/2022 0:55
Bob30/01/2022 23:5928/01/2022 0:56
Matt30/01/2022 23:5930/01/2022 11:57
Matt30/01/2022 23:5930/01/2022 11:58
Dan30/01/2022 23:594/02/2022 0:09
Dan30/01/2022 23:594/02/2022 0:09
Ash6/02/2022 23:593/02/2022 8:00
Ash6/02/2022 23:593/02/2022 8:00
Bob6/02/2022 23:592/02/2022 22:45
Bob6/02/2022 23:593/02/2022 22:31
Bob6/02/2022 23:594/02/2022 5:05
Bob6/02/2022 23:594/02/2022 5:05
Matt6/02/2022 23:594/02/2022 6:11
Matt6/02/2022 23:594/02/2022 6:11
Dan6/02/2022 23:594/02/2022 5:49
Dan6/02/2022 23:594/02/2022 5:49
Dan6/02/2022 23:594/02/2022 5:49
1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Blouey 
You can start with a calculated column using the followinng code:

Keep? = 
VAR CurrentName = Data[Name]
VAR CurrentTimePeriod = Data[TimePeriod]
VAR CurrentModifiedDate = Data[ModifiedDate]
VAR FilteredTable1 =
    CALCULATETABLE ( 
        Data,
        Data[Name] = CurrentName,
        Data[TimePeriod] = CurrentTimePeriod,
        REMOVEFILTERS ()
    )
VAR LastModifiedDate =
    MAXX (
        FilteredTable1,
        Data[ModifiedDate]
    )
RETURN
    IF (
        CurrentModifiedDate = LastModifiedDate,
        "Yes"
    )


Untitled.png
Then you can calculate a new table using this code:

 

FilteredTable = 
DISTINCT ( 
    CALCULATETABLE (
        Data,
        NOT ISBLANK ( Data[Keep?] )
    )
)

 

Please let me know if this answers your query.
You can find the Pbi file here https://www.dropbox.com/t/YhBedW8OGb8xrocH

View solution in original post

3 REPLIES 3
wdx223_Daniel
Super User
Super User

NewStep=Table.FromRecords(Table.Group(PreviousStepName,{"Name","TimePeriod"},{"n",each Table.Max(_,"ModifiedDate")})[n])

tamerj1
Super User
Super User

Hi @Blouey 
You can start with a calculated column using the followinng code:

Keep? = 
VAR CurrentName = Data[Name]
VAR CurrentTimePeriod = Data[TimePeriod]
VAR CurrentModifiedDate = Data[ModifiedDate]
VAR FilteredTable1 =
    CALCULATETABLE ( 
        Data,
        Data[Name] = CurrentName,
        Data[TimePeriod] = CurrentTimePeriod,
        REMOVEFILTERS ()
    )
VAR LastModifiedDate =
    MAXX (
        FilteredTable1,
        Data[ModifiedDate]
    )
RETURN
    IF (
        CurrentModifiedDate = LastModifiedDate,
        "Yes"
    )


Untitled.png
Then you can calculate a new table using this code:

 

FilteredTable = 
DISTINCT ( 
    CALCULATETABLE (
        Data,
        NOT ISBLANK ( Data[Keep?] )
    )
)

 

Please let me know if this answers your query.
You can find the Pbi file here https://www.dropbox.com/t/YhBedW8OGb8xrocH

amitchandak
Super User
Super User

@Blouey , You need to add an index column in the power query as all timestamps are the same

 

you can create a flag like , a new column, and use that in filter

if([index] = maxx(filter(Table, Table[Name] =earlier(Table[Name])  && Table[Modified Date] =earlier(Table[Modified Date]) ), [Index]) ,1,0)

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.