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
lchaplen
Helper II
Helper II

Identifying last date by user and dept and display on user list

I have data for a program where I need to display the project and all the client detail.  One piece of information is to identify whether or not the client in the program also had services under another program and the last intake in this other program.  

I have the information for the first part and have started the second part.  I have clients and if they are in the program and created a column field if they are a EA Client and if not Other.  What I need to identify is the latest Date if they are a EA Client and then display that date.  So for C000041 I would need to display the date 9/30/2022 and for C003447 display 12/21/2022 in a new field.  If the client is not an EA Client then I would want the client to still display with no date. So no filtering  Due to personal ID information I can't attache the pbix file. If I were using SQL it would be easy but I can't figure it out in DAX. 

 

Data

Client_CodeIntake_DateEA Client
C000041 Other
C00004112/27/2012EA Client
C0000411/13/2014EA Client
C0000413/24/2017EA Client
C0000418/2/2017EA Client
C00004112/26/2018EA Client
C00004112/31/2019EA Client
C0000411/5/2021EA Client
C00004112/17/2021EA Client
C0000419/30/2022EA Client
C000099 Other
C0000996/18/2014EA Client
C0000995/5/2022EA Client
C0000999/30/2022EA Client
C002104 Other
C0021041/14/2013EA Client
C0021044/15/2014EA Client
C00210412/23/2014EA Client
C0021041/15/2016EA Client
C0021041/20/2022EA Client
C0021049/30/2022EA Client
C003447 Other
C0034479/5/2013EA Client
C0034472/20/2014EA Client
C0034474/3/2014EA Client
C00344711/19/2015EA Client
C0034478/29/2016EA Client
C0034478/13/2018EA Client
C0034475/14/2019EA Client
C00344712/21/2022EA Client
1 ACCEPTED SOLUTION

Ok I figured it out.  I needed to create a column field

AssignProgDateifNone = if('rpt vw_Client_Programs'[EA Client]="Other",Date(1900,01,01),'rpt vw_Client_Programs'[Intake_Date])
to assign a date for "Other".  

Then I created a new column: 
LastProgramDate = CALCULATE(MAX('rpt vw_Client_Programs'[Intake_Date]),FILTER('rpt vw_Client_Programs','rpt vw_Client_Programs'[Client_Code]=EARLIER('rpt vw_Client_Programs'[Client_Code])))
And this got me the results I needed.  

IMHO this is a poor PowerBI design compared to a SQL solution.. Just my 2 cents.

 

View solution in original post

11 REPLIES 11
lchaplen
Helper II
Helper II

HI I am close now.. this is the formula I"m using.  The issue is I still need to return Clients if they have no Intake date with for example a bogus date 1/1/1900 or ideally Blank.  

 

Any ideas anyone?

 

LastProgram =
Var ClientID = max('rpt vw_Client_Programs'[Client_Code])
//Var ClientProgram = 'rpt vw_Client_Programs'[EA Client)
return
 Calculate(
        LASTDATE('rpt vw_Client_Programs'[Intake_Date]),
     FILTER('rpt vw_Client_Programs','rpt vw_Client_Programs'[Client_Code] = ClientID && ('rpt vw_Client_Programs'[EA Client]= "Other" || 'rpt vw_Client_Programs'[EA Client]= "EA Client"
     ))
      )
This is my desired result:
Client_CodeIntake_DateEA ClientDesired Result
C000041 Other1/1/1900
C00004112/27/2012 0:00EA Client9/30/2022
C0000411/13/2014 0:00EA Client9/30/2022
C0000413/24/2017 0:00EA Client9/30/2022
C0000418/2/2017 0:00EA Client9/30/2022
C00004112/26/2018 0:00EA Client9/30/2022
C00004112/31/2019 0:00EA Client9/30/2022
C0000411/5/2021 0:00EA Client9/30/2022
C00004112/17/2021 0:00EA Client9/30/2022
C0000419/30/2022 0:00EA Client9/30/2022
C003447 Other1/1/1900
C0034479/5/2013 0:00EA Client12/21/2022
C0034472/20/2014 0:00EA Client12/21/2022
C0034474/3/2014 0:00EA Client12/21/2022
C00344711/19/2015 0:00EA Client12/21/2022
C0034478/29/2016 0:00EA Client12/21/2022
C0034478/13/2018 0:00EA Client12/21/2022
C0034475/14/2019 0:00EA Client12/21/2022
C00344712/21/2022 0:00EA Client12/21/2022
Ashish_Mathur
Super User
Super User

Hi,

Do you want a calculated column formula or a measure solution?  Also, clearly show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi ideally a measure see Bolfri response.. that one is not working with error "A single value for column Client_Code in table Client_programs cannot be determined .  This can happen when a measure formula refers to column that contains many values without specifying an aggregation to get a single result

Hi,

I think a calculated column formula solution would work best.  This one does

Max date = if(Data[EA Client]="Other",BLANK(),CALCULATE(MAX(Data[Intake_Date]),FILTER(Data,Data[Client_Code]=EARLIER(Data[Client_Code])&&Data[EA Client]="EA client")))

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Ashish, Thanks would it allow me to put a dummy date for the "Other" as I want all clients returned as not all will be an EA Client and I need to know that and return it.  

Ashish I tried: 

LastProgramDate = if('rpt vw_Client_Programs'[EA Client]="Other",Date(1900,01,01),CALCULATE(MAX('rpt vw_Client_Programs'[Intake_Date]),FILTER('rpt vw_Client_Programs','rpt vw_Client_Programs'[Client_Code]=EARLIER('rpt vw_Client_Programs'[Client_Code]))))  And it only filters for EA_Client = EA_Client.  
 

Ok I figured it out.  I needed to create a column field

AssignProgDateifNone = if('rpt vw_Client_Programs'[EA Client]="Other",Date(1900,01,01),'rpt vw_Client_Programs'[Intake_Date])
to assign a date for "Other".  

Then I created a new column: 
LastProgramDate = CALCULATE(MAX('rpt vw_Client_Programs'[Intake_Date]),FILTER('rpt vw_Client_Programs','rpt vw_Client_Programs'[Client_Code]=EARLIER('rpt vw_Client_Programs'[Client_Code])))
And this got me the results I needed.  

IMHO this is a poor PowerBI design compared to a SQL solution.. Just my 2 cents.

 

Because its not a measure. Its calculated column.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Ok thanks I just posted an update.. any ideas to get this result?

bolfri
Super User
Super User

 

Client date = 
VAR current_client = 'Sample'[Client_Code]
VAR EA_Flag = 'Sample'[EA Client]
RETURN
    CALCULATE (
        LASTDATE ( 'Sample'[Intake_Date] ),
        FILTER (
            'Sample',
            'Sample'[Client_Code] = current_client
                && 'Sample'[EA Client] = EA_Flag
        )
    )

 

Result:

bolfri_1-1678403618150.png

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




HI thanks I'm getting the error:  "A single value for column Client_Code in table Client_programs cannot be determined . This can happen when a measure formula refers to column that contains many values without specifying an aggregation to get a single result

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.