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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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)

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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