Forum Discussion

andybamber's avatar
andybamber
Helper III
5 years ago

Dax Measure - Lastdate

Hello All!

 

I have a file of weekly data snapshots. The file has a snapshot date stamp

I have a measure:

headcount_Max_Wk = CALCULATE(DISTINCTCOUNT(SNAP_DWH_RES_RESOURCE[resource_key]),LASTDATE(SNAP_DWH_RES_RESOURCE[snaphot_stamp]))

 

The idea is i get a distinct count based on the latest date. When you create a bar chart and show the data by business area and year/month it correctly shows the headcount... and i can see its taking the last date for the month and giving the correct distinct headount

 

However on a second visual, where the bar chart is showing job role and year/month it doesnt work correctly... its overcounting this seems to be because some people have changed their job from 1 week to another, in the same month. As you can see below Name_2 and Name_3 are examples... how do i change my measure to ignore the 1st October row of data for each?

 

 

Cheers

 

Andy

10 Replies

  • For each Employee and Month Name you want to find the latest Day of the month. Once you have that you can then lookup the Job role for that user for that date.

     

    Do you need to do this in DAX or is Power Query an option too?

    • andybamber's avatar
      andybamber
      Helper III

      Hi There!

       

      Dax would be the preferred option, but i'm open to a power query solution..

       

      Cheers

       

      Andy

  • Anonymous's avatar
    Anonymous
    Not applicable

    andybamber  Hi , You can use this formula . I took employee Column to get distinct count by month .

     
     
    headcount_Max_Wk = CALCULATE(DISTINCTCOUNT(Sheet1[Employee]),LASTDATE(Sheet1[SnapShot Date Stamp]))

    • andybamber's avatar
      andybamber
      Helper III

      Anonymous  thanks for your reply... Apart from using Employee field in stead of resource Key (which is effectively the unique employee ID) your measure is probably the same as mine...  i think maybe you require some additional information... so the Month is being pulled into the visual from the linked Date Dimension table, the join is from snapshot date stamp to the data.. does that help?

       

      Cheers

       

      Andy

      • Anonymous's avatar
        Anonymous
        Not applicable

        andybamber : It Will Work for that as well . you have to define BI Directional Relationship in between datetable and  your master table then it will work fine for you .