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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
powerbifuddaa
Helper I
Helper I

Previous function employee

Hello,

I would like to make a calculated column with the PreviousFunctionName of an employee.

Person_BKFunctionChangedDateFunctionNamePreviousFunctionName
5551-12-2020function Anull of empty
5551-3-2022function Bfunction A
5551-8-2022function Cfunction B
55517-8-2023function Dfunction C

 

I can use DAX only.

Could somebody help me with this challenge?
Thank you! Regards, Elmer

1 ACCEPTED SOLUTION

ok i got you

you needed to be partitioned by pperson_bk

 

 

step0 : 

you need to fix the column functionchangedate to respect the following format : 

m-dd-yyyy

 

 

step1 :  go to power query and change the column functionchangeddate type from text to date 

Daniel29195_0-1705572401721.png

 

 

step 3 : in power query sort asc the first column : 

Daniel29195_1-1705572588293.png

 

step 4 :  

sort functionchangeddate column asc  

Daniel29195_2-1705572707882.png

 

 

save and apply. 

 

 

 

 

step 5 : 
use this measure now : 

Column =
var current_perosn = 'Table (7)'[Person_BK]
var current_date = 'Table (7)'[FunctionChangedDate]
var datasource =
    FILTER(
        all('Table (7)'[FunctionChangedDate],'Table (7)'[FunctionName],'Table (7)'[Person_BK]),
        'Table (7)'[Person_BK] = current_perosn && 'Table (7)'[FunctionChangedDate] <=current_date
        && 'Table (7)'[FunctionChangedDate] <=current_date
        )



return  
SELECTCOLUMNS(
offset(
    -1,
    datasource,
    ORDERBY('Table (7)'[FunctionChangedDate] , asc ),
    PARTITIONBY('Table (7)'[Person_BK])
),
[FunctionName]
)
 
 
Daniel29195_3-1705572910861.png

 

 

 

 

View solution in original post

18 REPLIES 18
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=LOOKUPVALUE(Data[FunctionName],Data[FunctionChangedDate],CALCULATE(MAX(Data[FunctionChangedDate]),FILTER(Data,Data[Person_BK]=EARLIER(Data[Person_BK])&&Data[FunctionChangedDate]<EARLIER(Data[FunctionChangedDate]))),[Person_BK],[Person_BK])

Hope this helps.

Ashish_Mathur_0-1705202041431.png

 


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

@Ashish_Mathur thank you for your help.

Maybe you can help me. Because your formula works fine when I make a separate tabel in powerbi with the columns I provided. But my model looks like this:

Table: Function with the columns FunctionName, Function_Key.

Table: Contract History with the columns Person_BK, FunctionChangeDate, Function_Key.

The relation is one (function) to many (contract history).

 

I tried to work with related:

LOOKUPVALUE (
    'Contract History'[@related_functionname],
    'Contract History'[FunctionChangedDate],
        CALCULATE (
            MAX ( 'Contract History'[FunctionChangedDate] ),
            FILTER (
                'Contract History',
                'Contract History'[Person_BK] = EARLIER ( 'Contract History'[Person_BK] )
                    && 'Contract History'[FunctionChangedDate]
                        EARLIER ( 'Contract History'[FunctionChangedDate] )
            )
        ),
    'Contract History'[Person_BK], 'Contract History'[Person_BK]
)

 

I get a circular dependency message.

Any idea how I can solve this?

Thank you very much. Regards, Elmer

Hi,

Just by looking at your formula and table layout, i cannot help you.  Share the tables in a format that can be pasted in an MS Excel file and show the expected result.


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

Hi @Ashish_Mathur ,

Here are the 2 tables:

Function (table)Contract History (table) 
FunctionNamePerson_BK
Function_KeyFunctionChangeDate
 Function_Key

The relation is one (function) to many (contract history).

 

Expected result: calculated column PreviousFunctionName

Person_BKFunctionChangedDateFunctionNamePreviousFunctionName
5551-12-2020function Anull of empty
5551-3-2022function Bfunction A
5551-8-2022function Cfunction B
55517-8-2023function Dfunction C

Hope this helps. Please let me know if you expected something else I should have handed to you.

Thank you very much. Regards, Elmer

Hi,

Share both tables in a format that can be pasted in an MS Excel file.


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

Hi @Ashish_Mathur  ,

I am afraid that I do not know what you mean.  

I have included the pbix file (PowerBI file). I hope that will help.

Thanx and regards, Elmer

Hi,

Your question has already been answered by another user.


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

Daniel29195_0-1705154665024.png

try this code  : 

Column =
var current_perosn = 'Table (4)'[Person_BK]
var current_date = 'Table (4)'[FunctionChangedDate]
var datasource =
    FILTER(
        all('Table (4)'[FunctionChangedDate],'Table (4)'[FunctionName]),
        'Table (4)'[Person_BK] = current_perosn && 'Table (4)'[FunctionChangedDate] <=current_date
        && 'Table (4)'[FunctionChangedDate] <=current_date
        )



return  
SELECTCOLUMNS(
offset(
    -1,
    datasource,
    ORDERBY('Table (4)'[FunctionChangedDate] , asc )
),
[FunctionName]
)

Thank you for your respons and help @Daniel29195.

Unfortunately this code doesn't work for me. I get an error after selectcolumns(..., [name1],...

Also I'm missing function c in your output. 

can you share the error  you are getting   ?

 

Hi @Daniel29195 

powerbifuddaa_0-1705564831418.png

The error I am getting: parameter is not the correct type.

Thank you. Regards, Elmer

what is weird is that from my side i didnt get any error . 

could you pllease try one of the following : 

1. add the table name before the column name , so instead of  [FunctionName] , write :  Table_Name[FunctionName] ( with table_name =  the table name you have in your model ) 

if this doesnt work,  

try this : 

SELECTCOLUMNS(
offset(
    -1,
    datasource,
    ORDERBY('Table (4)'[FunctionChangedDate] , asc )
),
"col" , Table_Name[FunctionName]
)
 
add the text in bold 
 
let me know if it works for you

Hi @Daniel29195 ,

I don't get an error anymore after adding the text in bold:

This looks good.

powerbifuddaa_0-1705568471257.png

 

After testing and adding more person_bk's I get an output that I didn't expect:

Person_BKFunctionChangedDateFunctionName@PreviousFunctionName
5551-12-2020function AProcesmanager 2
5551-3-2022function BOndernemersadviseur 1
5551-8-2022function CPractice Lead Infra
55517-8-2023function DProduct Owner 2
111116-10-2023Adviseur Business Support 1function D
11111-1-2024Adviseur Business Support 2Adviseur Business Support 1
11111-1-2014Medewerker Servicecenter 2 
11111-1-2022Ondernemersadviseur 1Teamleider IT Operations
11111-3-2023Ondernemersadviseur 1Product Owner
22221-3-2022Practice Lead Infrafunction B
22221-1-2014Procesmanager 2Medewerker Servicecenter 2
22221-10-2022Product Ownerfunction C
222215-3-2023Product Owner 1Ondernemersadviseur 1
22221-7-2023Product Owner 2Product Owner 1
22221-1-2021Teamleider IT Operationsfunction A
 

Any idea? Thank you for your help.

Kind regards, Elmer

@powerbifuddaa 

yes,

you need to sort the order of the table asc by functionchangedDate column , 

since the offset function is base on the order of this column . 

 

 

Daniel29195_0-1705569926017.png

click on the arrow of the column and sort it ascending, 

Daniel29195_1-1705569935425.png

 

 

if you have any questions please post it and i will try to help you .

 

@Daniel29195 ,

Thanks. Any idea how I directly can get this result:

Person_BKFunctionChangedDateFunctionName@PreviousFunctionName
5551-12-2020function A 
5551-3-2022function Bfunction A
5551-8-2022function Cfunction B
55517-8-2023function Dfunction C
11111-1-2014Medewerker Servicecenter 2 
11111-1-2022Ondernemersadviseur 1Medewerker Servicecenter 2
11111-3-2023Ondernemersadviseur 1Ondernemersadviseur 1
111116-10-2023Adviseur Business Support 1Ondernemersadviseur 1
11111-1-2024Adviseur Business Support 2Adviseur Business Support 1
22221-1-2014Procesmanager 2 
22221-1-2021Teamleider IT OperationsProcesmanager 2
22221-3-2022Practice Lead InfraTeamleider IT Operations
22221-10-2022Product OwnerPractice Lead Infra
222215-3-2023Product Owner 1Product Owner
22221-7-2023Product Owner 2Product Owner 1

Thanks for your help.

Kind regards, Elmer

ok i got you

you needed to be partitioned by pperson_bk

 

 

step0 : 

you need to fix the column functionchangedate to respect the following format : 

m-dd-yyyy

 

 

step1 :  go to power query and change the column functionchangeddate type from text to date 

Daniel29195_0-1705572401721.png

 

 

step 3 : in power query sort asc the first column : 

Daniel29195_1-1705572588293.png

 

step 4 :  

sort functionchangeddate column asc  

Daniel29195_2-1705572707882.png

 

 

save and apply. 

 

 

 

 

step 5 : 
use this measure now : 

Column =
var current_perosn = 'Table (7)'[Person_BK]
var current_date = 'Table (7)'[FunctionChangedDate]
var datasource =
    FILTER(
        all('Table (7)'[FunctionChangedDate],'Table (7)'[FunctionName],'Table (7)'[Person_BK]),
        'Table (7)'[Person_BK] = current_perosn && 'Table (7)'[FunctionChangedDate] <=current_date
        && 'Table (7)'[FunctionChangedDate] <=current_date
        )



return  
SELECTCOLUMNS(
offset(
    -1,
    datasource,
    ORDERBY('Table (7)'[FunctionChangedDate] , asc ),
    PARTITIONBY('Table (7)'[Person_BK])
),
[FunctionName]
)
 
 
Daniel29195_3-1705572910861.png

 

 

 

 

Thanks @Daniel29195 

Although I get an error again (Parameter is not the correct type), this works!

powerbifuddaa_1-1705673078224.png

If I remove the "PARTITIONBY('Table (2)'[Person_BK])" part, it also works.

Thank you for your help

@powerbifuddaa 
glad i could help you out .

 

Feel free to mention my name in your future questions within the community. I would be more than happy to assist you further. 

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Carousel June 2024

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

2
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.