Forum Discussion

awff's avatar
awff
Helper III
4 years ago
Solved

Creating a latest occurrence column

Hello fellow PBI'ers,

 

I am hoping to create a calculated column which identifies the latest occurrence with each account based on a few criterias. The result is as per the "Desired_Result" column in the mock table below:

 

Task:

  • For each account, Identify the latest maintenance occurrence by end date for each product. The result should be a string.

 

AccountNameEndDate  FamilyProductDesired_Result
Account 11-Jan-22MaintenanceALatest
Account 11-Mar-21MaintenanceA 
Account 11-Jul-22SoftwareA 
Account 21-Apr-20SoftwareB 
Account 21-Apr-22SoftwareC 
Account 31-Sep-21MaintenanceCLatest
Account 41-Sep-22MaintenanceA 
Account 41-Nov-22MaintenanceALatest
Account 41-Jan-21MaintenanceBLatest
Account 41-Aug-20SoftwareC 
Account 41-Aug-20MaintenanceCLatest

 

Would anyone be able to assist with this? I've tried the common SWITCH(TRUE() method but i can't seem to break it down to an products per account level...

 

Thanks!

  • Try this

     

     

    _Latest Result Column= 
    
    Var Acc = 'Latest Occurence'[AccountName]
    Var Pro = 'Latest Occurence'[Product]
    Var dt = CALCULATE(MAX('Latest Occurence'[EndDate  ]),FILTER('Latest Occurence','Latest Occurence'[AccountName]=Acc && 'Latest Occurence'[Product]=Pro && 'Latest Occurence'[Family]="Maintenance"))
    
    RETURN
    IF(dt='Latest Occurence'[EndDate  ] && 'Latest Occurence'[Family]="Maintenance","Latest","")
    

     

3 Replies

  • Hi,

    Please check the below picture and the attached pbix file.

     

     

    Desired Result CC =
    IF (
    NOT ( Data[Family] = "Maintenance" ),
    BLANK (),
    SWITCH (
    TRUE (),
    VAR currentaccountname = Data[AccountName]
    VAR currentproduct = Data[Product]
    VAR newtable =
    FILTER (
    Data,
    Data[AccountName] = currentaccountname
    && Data[Product] = currentproduct
    && Data[Family] = "Maintenance"
    )
    VAR maxdate_newtable =
    MAXX ( newtable, Data[EndDate] )
    RETURN
    Data[EndDate] = maxdate_newtable, "Latest"
    )
    )

  • FarhanAhmed's avatar
    FarhanAhmed
    Community Champion

    Try this

     

     

    _Latest Result Column= 
    
    Var Acc = 'Latest Occurence'[AccountName]
    Var Pro = 'Latest Occurence'[Product]
    Var dt = CALCULATE(MAX('Latest Occurence'[EndDate  ]),FILTER('Latest Occurence','Latest Occurence'[AccountName]=Acc && 'Latest Occurence'[Product]=Pro && 'Latest Occurence'[Family]="Maintenance"))
    
    RETURN
    IF(dt='Latest Occurence'[EndDate  ] && 'Latest Occurence'[Family]="Maintenance","Latest","")