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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ganes
Helper I
Helper I

Need help to get count of new and deleted ids for each Date

I have a table called mytable with an 2 colum Report_Date and id.
Each day few new ids gets created and few gets deleted.
I want to get the count of ids that are newly added for each date in the Report_Date colum
I want to get the count of ids that are deleted for each date n the Report_Date colum
I want to get the remaining unique count of ids that are still present for each date n the Report_Date colum

For example lets take an example : we have entries in the mytable as below

i want below output in Dax

 

MicrosoftTeams-image.png



1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Create a proper date table, marked as a date table, and you can create measures like

Count new ids =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR CurrentIDs =
    VALUES ( 'Table'[id] )
VAR YesterdayIDs =
    CALCULATETABLE ( VALUES ( 'Table'[id] ), 'Date'[Date] = ReferenceDate - 1 )
VAR Result =
    COUNTROWS ( EXCEPT ( CurrentIDs, YesterdayIDs ) )
RETURN
    Result

Count deleted ids =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR CurrentIDs =
    VALUES ( 'Table'[id] )
VAR YesterdayIDs =
    CALCULATETABLE ( VALUES ( 'Table'[id] ), 'Date'[Date] = ReferenceDate - 1 )
VAR Result =
    COUNTROWS ( EXCEPT ( YesterdayIDs, CurrentIDs ) )
RETURN
    Result

Total IDs = COUNTROWS('Table')

View solution in original post

9 REPLIES 9
johnt75
Super User
Super User

Create a proper date table, marked as a date table, and you can create measures like

Count new ids =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR CurrentIDs =
    VALUES ( 'Table'[id] )
VAR YesterdayIDs =
    CALCULATETABLE ( VALUES ( 'Table'[id] ), 'Date'[Date] = ReferenceDate - 1 )
VAR Result =
    COUNTROWS ( EXCEPT ( CurrentIDs, YesterdayIDs ) )
RETURN
    Result

Count deleted ids =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR CurrentIDs =
    VALUES ( 'Table'[id] )
VAR YesterdayIDs =
    CALCULATETABLE ( VALUES ( 'Table'[id] ), 'Date'[Date] = ReferenceDate - 1 )
VAR Result =
    COUNTROWS ( EXCEPT ( YesterdayIDs, CurrentIDs ) )
RETURN
    Result

Total IDs = COUNTROWS('Table')

Hi  @johnt75 ,

Thanks for the solution it is working for 2 consecutive dates but Not working for historical date.
Can you please guide me how to make it work for previous dates and Future Dates. 

Basically I want to show a Line Chart to represnt count of new ids and deleted Ids week wise and month wiseMicrosoftTeams-image (1).png

I think you'd need separate measures for weekly and monthly. You could have the monthly like

Count new ids monthly =
VAR CurrentIDs =
    VALUES ( 'Table'[id] )
VAR YesterdayIDs =
    CALCULATETABLE ( VALUES ( 'Table'[id] ), DATEADD ( 'Date'[Date], -1, MONTH ) )
VAR Result =
    COUNTROWS ( EXCEPT ( CurrentIDs, YesterdayIDs ) )
RETURN
    Result

and for weekly just change -1, MONTH, to -7, DAY.

Hi @johnt75 ,

Thank you very much. This worked. Previously it was not working because data was inconsitent. 

Hi @johnt75 , Thanks again for sharing the query. However, it is only giving result for recent date and not for all the dates in the Report_Date colum. My requirement is to get each date in the Report_Date colum in mytable.

for eg. - in the attached image you can find the value is comming only for March 17 and not for previous dates. Also, the for previous dates the new ids showing total count of ids for that date not ones which got added newly from previous date.



Will be gratefull if you can share the logic to get all the dates vauleMicrosoftTeams-image (2).png

I'm not sure I fully understand the problem. You have a table with data for non-consecutive dates. When you plot, e.g. the number of new ids on a monthly or weekly chart, what exactly are you expecting to see? The number of ids which existed at the end of the period but did not exist at the end of the previous period ? Or some sort of daily aggregation ?

Hi @johnt75,
yes, my requirement is to show the count of ids that were deleted and newly added at the end of period. I have tried to explain my requirement in the screenshot attached. hope you got some clarrity

ganes_0-1679061818771.png

 

You'll need a date table, marked as a date table, which you will use in all visuals. You can use week commencing, week ending or something similar as the column in your visuals.

Then you can create a measure like

Weekly new ids =
VAR EndCurrentWeek =
    MAX ( 'Date'[Date] )
VAR EndPrevWeek = EndCurrentWeek - 7
VAR LastDateThisWeek =
    CALCULATE (
        MAX ( 'Table'[Reporting date] ),
        DATESBETWEEN ( 'Date'[Date], EndPrevWeek + 1, EndCurrentWeek )
    )
VAR LastDateLastWeek =
    CALCULATE (
        MAX ( 'Table'[Reporting date] ),
        DATESBETWEEN ( 'Date'[Date], EndPrevWeek - 6, EndPrevWeek )
    )
VAR PrevIDs =
    CALCULATETABLE ( VALUES ( 'Table'[id] ), 'Date'[Date] = LastDateLastWeek )
VAR CurrentIDs =
    CALCULATETABLE ( VALUES ( 'Table'[id] ), 'Date'[Date] = LastDateThisWeek )
RETURN
    COUNTROWS ( EXCEPT ( CurrentIDs, PrevIDs ) )

which gets the last date for which you have data in the current week and the previous week, and compares the ids from those dates.

Hi @johnt75 ,

Thanks again for the response. However, I tried to follow whatever you advised but it is still not returning as per the requirement.
It is returning only id count for the date. But not how many id deleted and new id created from previous date.

ganes_0-1679073329290.png

Requirement is to get the values as shown below for March 17.

ganes_1-1679073456788.png

Similarly need values for other dates Mar 07, Mar 09, Mar 13, Mar 16 and future dates as well.


This is the table I created as per your advise 

Date = CALENDAR(DATE(2023,1,1), DATE(2099,12,31))


This is the new measure :

Weekly new id =
VAR EndCurrentWeek =
    MAX ( 'Date'[Date] )
VAR EndPrevWeek = EndCurrentWeek - 7
VAR LastDateThisWeek =
    CALCULATE (
        MAX ( 'mytable'[Report_Date]),
        DATESBETWEEN ( 'Date'[Date], EndPrevWeek + 1, EndCurrentWeek )
    )
VAR LastDateLastWeek =
    CALCULATE (
        MAX ( 'mytable'[Report_Date]),
        DATESBETWEEN ( 'Date'[Date], EndPrevWeek - 6, EndPrevWeek )
    )
VAR PrevIDs =
    CALCULATETABLE ( VALUES ( 'mytable'[id]), 'Date'[Date] = LastDateLastWeek )
VAR CurrentIDs =
    CALCULATETABLE ( VALUES ( 'mytable'[id] ), 'Date'[Date] = LastDateThisWeek )
RETURN
    COUNTROWS ( EXCEPT ( CurrentIDs, PrevIDs ) )


 I am updating the mytable.pbix file link here for more clarity.

https://onedrive.live.com/?authkey=%21AC7wjU%5FAXMZtThA&cid=82C96F93A7FA75E9&id=82C96F93A7FA75E9%211...


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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