Forum Discussion

yve214's avatar
yve214
Helper III
4 years ago
Solved

Can't get the recent Date Values

Hi there,

 

I am trying to get the recent date value for the table below. 

 

I have tried the max and lastdate function but I cant seem to get the results i am expecting. 

I was able to get a seperate latest effective date column with Measure = Calculate(MAX(Table(Effective_Date), Allexcept(Table, table(id))

 

Table:

IDEmp_IDIntervalEffective_DateScore
11001001/01/20203.1

2

1001008/26/20203.3
31001311/20/20203.5
41001505/05/20203.2
5100152/1/20214.1
6100201/1/20222.0

 

Expected result if i want to see the recent date values if i filter by interval 0.

 

IDEmp_IDEffective_DateScore
210018/26/2020

3.3

610021/1/20222.0

or if i dont filter any of the intervals i should get all client IDs with a recent date value witht their corresponding intervals.

 

IDEmp_IDIntervalEffective_DateScore
2100108/26/2020

3.3

6100201/1/20222.0
31001311/20/20203.5
5100152/1/20214.1

 

  • Hello yve214

    I was able to get this to work by creating a new table with the following DAX:

    New table = 
    ADDCOLUMNS(
        SUMMARIZE( 'Table', 'Table'[Emp_ID], 'Table'[Interval] ),
        "Effective Date", CALCULATE( MAX( 'Table'[Effective_Date] ) ),
        "Score", CALCULATE( MAX( 'Table'[Score] )),
        "ID", CALCULATE( MAX( 'Table'[ID] ) )
    )

     

    I created a .pbix file that you can download here


    -Steve

  • Hi yve214. Ah, I think understand now. See if this works for you:

    Count of Emp IDs =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Emp_ID] ),
        FILTER (
            'Table',
            VAR CurrentRowEmpID = 'Table'[Emp_ID]
            RETURN
                VAR IntervalZeroEffectiveDate =
                    CALCULATE (
                        MIN ( 'Table'[Effective_Date] ),
                        ALL ( 'Table' ),
                        'Table'[Interval] = 0
                            && 'Table'[Emp_ID] = CurrentRowEmpID
                    )
                RETURN
                    'Table'[Interval] = 6
                        && 'Table'[Effective_Date] > IntervalZeroEffectiveDate
        )
    )

11 Replies

  • SteveHailey's avatar
    SteveHailey
    Solution Specialist

    Hello yve214

    I was able to get this to work by creating a new table with the following DAX:

    New table = 
    ADDCOLUMNS(
        SUMMARIZE( 'Table', 'Table'[Emp_ID], 'Table'[Interval] ),
        "Effective Date", CALCULATE( MAX( 'Table'[Effective_Date] ) ),
        "Score", CALCULATE( MAX( 'Table'[Score] )),
        "ID", CALCULATE( MAX( 'Table'[ID] ) )
    )

     

    I created a .pbix file that you can download here


    -Steve

    • yve214's avatar
      yve214
      Helper III

      SteveHailey Thank you so much, dont know why i didnt think of a summarize function. Worked like magic.

    • yve214's avatar
      yve214
      Helper III

      SteveHailey ,

       

      Please can i ask one more question? I am trying to "count the emp IDs where the interval is 6 making sure the dates at interval 6 is greater like (effective date at the 6 interval > the effective date at interval 0). Is that something you can help me with.

       

      Here is how i approached it. I created two date measures for both interval 0 and interval 6. I did a if((date_at_interval_6) > (date_at_interval_0) && table[interval] = 6, distinctcount(table[emp_ID]). But i keep getting blank.

      • SteveHailey's avatar
        SteveHailey
        Solution Specialist

        Hi yve214

        Give this a try:

        Count of Emp IDs = 
        COUNTROWS(
            FILTER(
                'Table',
                VAR CurrentRowEmpID = 'Table'[Emp_ID]
                RETURN
                    VAR IntervalZeroEffectiveDate =
                        CALCULATE(
                            MIN( 'Table'[Effective_Date] ),
                            ALL( 'Table' ),
                            'Table'[Interval] = 0 && 'Table'[Emp_ID] = CurrentRowEmpID
                        )
                    RETURN
                        'Table'[Interval] = 6
                            && 'Table'[Effective_Date] > IntervalZeroEffectiveDate
            )
        )
  • emjp's avatar
    emjp
    Frequent Visitor

    I am not sure if Power BI is the best choice for this task. The result can be easily achieved in excel with a slicer. 

     

    ...

     

     

    my Power BI Version, without a DAX Expresion

     

     

    • yve214's avatar
      yve214
      Helper III

      Thank you emjp , I was able to get it from using a summarize (select statement) function.