Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Last transaction dynamically

Hello!

I'm trying to find the lastest transaction in a dynamic period, I have checked another posts in the forum but they doesnt work.

I have tried everything and I can get them but the dynamic calculation is so slow like 2 min aprox.

I'll let here a example of my problem:

Data:

IDDate (DD/MM/YYYY)Type
110/10/2020A
108/12/2020B
212/11/2020A

Results expected:

**First example (Filter: 01/01/2019-31/11/2020)

TypeCount
A2
Total2

 

**Second example (Filter: 01/01/2019-31/12/2020)

TypeCount
A1
B1
Total2

 

If someone can help, i'll be really happy!

 

Thank you!!!

  • Hi Anonymous ,

    Try the following formula:

    Max_Date = 
    CALCULATE(
        MAX('Table'[Date]),
        ALLSELECTED('Table'),
        GROUPBY('Table','Table'[ID])
    )
    Measure = 
    var result = 
        CALCULATE(
            COUNT('Table'[ID]),
            FILTER(
                ALLSELECTED('Table'),
                'Table'[Date] = [Max_Date]
                && 'Table'[Type] = MAX('Table'[Type])
            )
        )
    return 
        IF(
            HASONEFILTER('Table'[Type]),
            result,
            DISTINCTCOUNT('Table'[ID])
        )

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

    Best Regards,
    Winniz

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

13 Replies

  • Anonymous , Try a measure like

     

    Status =
    VAR __id = MAX ('Table'[ID] )
    VAR __date = CALCULATE ( MAX('Table'[Date] ), ALLSELECTED ('Table' ), 'Table'[ID] = __id )
    CALCULATE ( count('Table'[Status] ), VALUES ('Table'[ID] ),'Table'[ID] = __id,'Table'[Date] = __date )

    • Anonymous's avatar
      Anonymous
      Not applicable

      Unfortunatelly, It doesnt seems to work, every type have value 1 with that measure.

  • Arentir's avatar
    Arentir
    Resolver III

    Hi Anonymous ,

    I didn't quite understand the result expected example part. From the problem description I understand you want to show :

    In case all dates are selected

    IDDate (DD/MM/YYYY)Type
    108/12/2020B

     

    In calse 01/01/2020 to 30/11/2020 is selected

    IDDate (DD/MM/YYYY)Type
    212/11/2020A

     

    is that correct?

    • Anonymous's avatar
      Anonymous
      Not applicable

      I want to know the count of each type for the lastest transaction of a certain period of time, the period will be a slicer, so it needs to be dynamic.

       

      In case all date are selected the lastest transaction for each ID are the ones that you said.

  • v-kkf-msft's avatar
    v-kkf-msft
    Community Support

    Hi Anonymous ,

    Try the following formula:

    Measure = 
    var MaxDate = 
        CALCULATE(
            MAX('Table'[Date]),
            ALLSELECTED('Table'),
            GROUPBY('Table','Table'[ID])
        )
    return 
        CALCULATE(
            COUNT('Table'[Type]),
            GROUPBY(
                FILTER(
                    ALLSELECTED('Table'),
                    'Table'[Date] = MaxDate
                ),
                'Table'[Type]
            )
        )

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

    Best Regards,
    Winniz

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you!!

      I see a problem in your measure, the first example is wrong because the total should be 2, and it shows 1.

       

      • v-kkf-msft's avatar
        v-kkf-msft
        Community Support

        Hi Anonymous ,

        Try the following formula:

         

        Measure = 
        var MaxDate = 
            CALCULATE(
                MAX('Table'[Date]),
                ALLSELECTED('Table'),
                GROUPBY('Table','Table'[ID])
            )
        var result = 
            CALCULATE(
                COUNT('Table'[Type]),
                GROUPBY(
                    FILTER(
                        ALLSELECTED('Table'),
                        'Table'[Date] = MaxDate
                    ),
                    'Table'[Type]
                )
            )
        return 
            IF(
                HASONEFILTER('Table'[Type]),
                result,
                DISTINCTCOUNT('Table'[ID])
            )

         

        If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

        Best Regards,
        Winniz

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