cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
henkka
Helper II
Helper II

How to find latest agreement by employee and create a table

Hi, I have a Workagreement table, which includes Employee.id and Workagreement.id. I need to create a calculated table for the latest workagreement (biggest Workagreement.id) by employee but not able to find a solution. Please maybe someone here can help me.

My measure:

Newest agreement by employee =
-- get all employees to var --
VAR allagreement =
VALUES(FactWorkagreement[Employee.id])

--get all workagreement ids --
var agreementids = VALUES(FactWorkagreement[Workagreement.id])

--Get the latest agreement for the employee. Latestagreement = MAX workagreementid, All latest agreement = CALCULATE ( [LatestAgreement], ALL ( 'FactWorkagreement'[Workagreement.id] ) )
VAR result1 =
CALCULATE (
    COUNTX ( FactWorkagreement , FactWorkagreement[Workagreement.id] ),
    FILTER (agreementids, [LatestAgreement] = [All latest agreement] )
        )
--find the latest agreement by employee
VAR result =
FILTER ( allagreement , result1 )  
RETURN
CALCULATETABLE (
        Summarize ( FactWorkagreement ,
                    FactWorkagreement[Employee.id] , FactWorkagreement[Workagreement.id] ) , result
               )
 
With this I'm getting a table, but it includes all of the workagreements, not only the latest by employee.
henkka_0-1669008650755.png

 

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

Hi @henkka ,

 

Please follow these steps:

(1) Create new table and measure

Max = CALCULATE(MAX('Table'[Workagreement.id]),FILTER(ALL('Table'),'Table'[Employee.id]= MAX('Table'[Employee.id])))

 

Table 2 = FILTER(ALL('Table'),'Table'[Workagreement.id]=[Max])

 

(2)Final output

vjialluomsft_0-1669013660824.png

 

 

Best Regards,

Gallen Luo

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-jialluo-msft
Community Support
Community Support

Hi @henkka ,

 

Please follow these steps:

(1) Create new table and measure

Max = CALCULATE(MAX('Table'[Workagreement.id]),FILTER(ALL('Table'),'Table'[Employee.id]= MAX('Table'[Employee.id])))

 

Table 2 = FILTER(ALL('Table'),'Table'[Workagreement.id]=[Max])

 

(2)Final output

vjialluomsft_0-1669013660824.png

 

 

Best Regards,

Gallen Luo

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you very much, modified this a bit as I don't need other columns from the table, but works like a charm!

 

If someone seeks this and has similar need  that I have, modify the second part of the dax as this:

FILTER (
    ALLSELECTED ( 'FactWorkagreement'[Employee.id] , FactWorkagreement[Workagreement.id] ) ,
    'FactWorkagreement'[Workagreement.id]=[Max]
    )

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors