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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Mi_80
Helper I
Helper I

How to get most recent record by id in a table and then count records

Hi,

 

I am really struggling to find a way to take a table of updates, then group those updates by an ID, and only take the latest records for each id and use that data to count and visualise (which can be dynamically filtered).

 

So for example a table of updates

update datecategory typeid
1/1/21normal1
3/1/21low1
1/1/21high2
2/1/21normal2
4/1/21low2
2/1/21high1

 

so I would like to turn this (dynamically) to if filtered date = 2/1/21

 

update datecategory typeid
2/1/21high1
2/1/21normal2

 

so I only have the most recent entry for each ID.

 

Then I would like to take that data to be able to count and visualise e.g. Count ID that have category type normal...in above case equal 1 and show this is bar chart or line graph where I can show the count of category types each month, based on most rcent records.

 

Hope this makes sense.

 

Do far using the below measure I am able to create a table woth the most rcent category type by distinct partner id

 

Measure 2 =
CALCULATE(FIRSTNONBLANK(new_partnerlandscapehistory[Value],1),FILTER(new_partnerlandscapehistory,new_partnerlandscapehistory[createdon] = MAX(new_partnerlandscapehistory[createdon])))
 Thanks for your help
3 REPLIES 3
Mi_80
Helper I
Helper I

, I saw this solution in a different thread and the logic looks like what I need but when I try to use the INDEX function it says it doesn't exist...any ideas why?

You need to update your version of Power BI Desktop. I think INDEX was introduced in the December 2022 update.

johnt75
Super User
Super User

You could create a measure like

Num IDs =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR SummaryTable =
    CALCULATETABLE (
        INDEX (
            1,
            'Table',
            ORDERBY ( 'Table'[update date], DESC ),
            PARTITIONBY ( 'Table'[id] )
        ),
        'Date'[Date] <= ReferenceDate
    )
VAR Result =
    COUNTROWS ( SummaryTable )
RETURN
    Result

To stop Power BI complaining about possible duplicate rows you may need to add a column to your fact table to uniquely identify each row. If you don't already have a column like that you can use Power Query to add an index column. In the Model view select the fact table and mark the unique column as the key for the table.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.