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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

New and deleted records per month

Hi,

I have this kind of data. 

monthsubscriptionresourcegroupresourcename
2021-04subs1rg2rn4
2021-04subs1rg2rn5
2021-04subs1rg2rn6
2021-05subs1rg1rn1
2021-05subs1rg1rn2
2021-05subs1rg1rn3
2021-05subs1rg2rn4
2021-05subs1rg2rn5
2021-05subs1rg2rn6
2021-06subs1rg1rn1
2021-06subs1rg1rn2
2021-06subs1rg1rn3
2021-06subs1rg1rn7

 

My goal is to show what resource groups and/or resources are being newly created or deleted each month. 

 

Target outputs:

 

RG-level (newly created)

monthresourcegroupnewRG
2021-04rg2TRUE
2021-05rg2FALSE
2021-05rg1TRUE
2021-06rg1FALSE

 

Resource-level (newly created)

monthresourcenamenewResource
2021-04rn4TRUE
2021-04rn5TRUE
2021-04rn6TRUE
2021-05rn4FALSE
2021-05rn5FALSE
2021-05rn6FALSE
2021-05rn1TRUE
2021-05rn2TRUE
2021-05rn3TRUE
2021-06rn1FALSE
2021-06rn2FALSE
2021-06rn3FALSE
2021-06rn7TRUE

 

RG-level (deleted)

monthresourcegroupdelRG
2021-04rg2FALSE
2021-05rg2FALSE
2021-05rg1FALSE
2021-06rg2TRUE
2021-06rg1

FALSE

 

Resource-level (deleted)

monthresourcenamedelResource
2021-04rn4FALSE
2021-04rn5FALSE
2021-04rn6FALSE
2021-05rn4FALSE
2021-05rn5FALSE
2021-05rn6FALSE
2021-05rn1FALSE
2021-05rn2FALSE
2021-05rn3FALSE
2021-06rn1FALSE
2021-06rn2FALSE
2021-06rn3FALSE
2021-06rn7FALSE
2021-06rn4TRUE
2021-06rn5TRUE
2021-06rn6TRUE

 

I found this but in my case here, there is no related sales or cost.

https://community.powerbi.com/t5/Community-Blog/Customer-Retention-Part-1-Month-on-Month-Retention/b...

I found this another one, but it does not work quite well compared to the solution from the previous link.

https://community.powerbi.com/t5/Desktop/Comaring-data-based-on-date/m-p/145820

For example, RG1 exists on 2021-03 and 2021-05, but not on 2021-04. It will not be shown as new RG in 2021-05, since it was existing or has previous records last 2021-03. 

 

Would like to have somehow similar logic with the 1st link, but I can't figure it out.

  • New:  if resourcegroup/resourcename is NOT blank in current month and blank in the previous month
  • Deleted: if resourcegroup/resourcename is blank in current month and NOT blank in the previous month

 

Thanks in advance for the help!

1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

The below is what you want(the upper two is create newly,the below two is delete) :

vluwangmsft_0-1623999276968.png

Following is steps:

newly create:

rglevlenew =
IF (
    CALCULATE (
        MIN ( 'Table'[month] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[resourcegroup] = MAX ( 'Table'[resourcegroup] )
        )
    )
        = MAX ( 'Table'[month] ),
    TRUE (),
    FALSE ()
)
rsourcenew =
IF (
    CALCULATE (
        MIN ( 'Table'[month] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[resourcename] = MAX ( 'Table'[resourcename] )
        )
    )
        = MAX ( 'Table'[month] ),
    TRUE (),
    FALSE ()
)

 

Delete:

(group)

new table:

Table2 = CROSSJOIN(VALUES('Table'[month]),VALUES('Table'[resourcegroup]))

then create new column by the following dax:

iflastmonwithout =
LOOKUPVALUE (
    'Table'[month],
    'Table'[resourcegroup], Table2[resourcegroup],
    'Table'[month],
        DATE ( YEAR ( Table2[month] ), MONTH ( Table2[month] ) - 1, DAY ( Table2[month] ) ),
    0
)
ifthisonwithout =
LOOKUPVALUE (
    'Table'[month],
    'Table'[resourcegroup], Table2[resourcegroup],
    'Table'[month], Table2[month],
    0
)
pd = if(Table2[ifthisonwithout]=0&&Table2[iflastmonwithout]<>0,TRUE(),FALSE())

get the below:

vluwangmsft_1-1623999669787.png

resourcename:

Table3 = CROSSJOIN(VALUES('Table'[month]),VALUES('Table'[resourcename]))
iflastmonwithout = LOOKUPVALUE('Table'[month],'Table'[resourcename],Table3[resourcename], 'Table'[month],DATE(YEAR(Table3[month]),MONTH(Table3[month])-1,DAY(Table3[month])),0)
ifthisonwithout = LOOKUPVALUE('Table'[month],'Table'[resourcename],Table3[resourcename], 'Table'[month],Table3[month],0)
pd = if(Table3[ifthisonwithout]=0&&Table3[iflastmonwithout]<>0,TRUE(),FALSE())

vluwangmsft_2-1623999798195.png

 

 

Wish it is helpful for you!

 

Best Regards

Lucien

View solution in original post

3 REPLIES 3
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

The below is what you want(the upper two is create newly,the below two is delete) :

vluwangmsft_0-1623999276968.png

Following is steps:

newly create:

rglevlenew =
IF (
    CALCULATE (
        MIN ( 'Table'[month] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[resourcegroup] = MAX ( 'Table'[resourcegroup] )
        )
    )
        = MAX ( 'Table'[month] ),
    TRUE (),
    FALSE ()
)
rsourcenew =
IF (
    CALCULATE (
        MIN ( 'Table'[month] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[resourcename] = MAX ( 'Table'[resourcename] )
        )
    )
        = MAX ( 'Table'[month] ),
    TRUE (),
    FALSE ()
)

 

Delete:

(group)

new table:

Table2 = CROSSJOIN(VALUES('Table'[month]),VALUES('Table'[resourcegroup]))

then create new column by the following dax:

iflastmonwithout =
LOOKUPVALUE (
    'Table'[month],
    'Table'[resourcegroup], Table2[resourcegroup],
    'Table'[month],
        DATE ( YEAR ( Table2[month] ), MONTH ( Table2[month] ) - 1, DAY ( Table2[month] ) ),
    0
)
ifthisonwithout =
LOOKUPVALUE (
    'Table'[month],
    'Table'[resourcegroup], Table2[resourcegroup],
    'Table'[month], Table2[month],
    0
)
pd = if(Table2[ifthisonwithout]=0&&Table2[iflastmonwithout]<>0,TRUE(),FALSE())

get the below:

vluwangmsft_1-1623999669787.png

resourcename:

Table3 = CROSSJOIN(VALUES('Table'[month]),VALUES('Table'[resourcename]))
iflastmonwithout = LOOKUPVALUE('Table'[month],'Table'[resourcename],Table3[resourcename], 'Table'[month],DATE(YEAR(Table3[month]),MONTH(Table3[month])-1,DAY(Table3[month])),0)
ifthisonwithout = LOOKUPVALUE('Table'[month],'Table'[resourcename],Table3[resourcename], 'Table'[month],Table3[month],0)
pd = if(Table3[ifthisonwithout]=0&&Table3[iflastmonwithout]<>0,TRUE(),FALSE())

vluwangmsft_2-1623999798195.png

 

 

Wish it is helpful for you!

 

Best Regards

Lucien

amitchandak
Super User
Super User

@Anonymous , In this blog chnage LMTD like

https://community.powerbi.com/t5/Community-Blog/Customer-Retention-Part-1-Month-on-Month-Retention/ba-p/1361529

 

all before this month

LMTD = calculate([Sales],Filter(All('Date'),'Date'[Date] <= eomonth(max('Date'[Date]),-1)))	

 

 

create date using month year

date = Date(left([Month Year],4), right([Month Year],2),1)

 

 

Anonymous
Not applicable

My month column is already marked as Date data type within the same table, so it already has the date hierarchy.

JVA_0-1623755738563.png

When I try to create a measure, it cannot detect automatically the column needed for the CALCULATE function. It only detects existing measures that I have already created before. I would like to not include the [Sales] or [Cost] in the logic, if possible. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.