Forum Discussion

itsmeanuj's avatar
itsmeanuj
Helper IV
3 years ago
Solved

Max value based on dynamic date filter

I need to calculate something similar to the "partition by" function in SQL. 

 

My data contains multiple instances of IDs. I need to create a measure that would pick up the latest value of the "Call_flag" column (first calculate max "created_on" and then max "Stamp" column) for each unique ID & Product Combination. This means that the total count should show the count of unique ID&Product combinations. e.g. for Product A, the count of IDs would be 4 with the split of 3 "1s" (ID = 242977761642152961, 929999783480788916, 932585828936911719) and 1 "0"( ID = 932778067030379386".  

if the latest (first calculate max "created_on" and then max "Stamp" column) ID product combination has a value of 1 for "Call_flag" then, consider 1 and similarly 0 if the latest value is 0

 

PRODUCT_NAMEORGANIZATION_NAMEIDCHANGED_ONHAS_CALLSIS_TREATINGCALL_FLAGSTAMP
Product AA2429777616421529612020/04/200112020/04/21
Product AA2429777616421529612020/04/200102020/04/20
Product AA2429777616421529612020/03/200012020/04/22
Product AA2429777616421529612020/03/200002020/03/20
Product AB9299997834807889162021/05/031112021/05/04
Product AB9299997834807889162021/05/031112021/05/03
Product AB9299997834807889162021/04/030012021/04/04
Product AB9299997834807889162021/04/030012021/04/03
Product AD9325858289369117192023/09/020112023/09/03
Product AD9325858289369117192023/09/020112023/09/02
Product AD9325858289369117192023/02/021112023/02/03
Product AD9325858289369117192023/02/021112023/02/02
Product AC9327780670303793862022/07/160102022/07/17
Product AC9327780670303793862022/07/160102022/07/16
Product AC9327780670303793862022/04/161002022/04/17
Product AC9327780670303793862022/04/161002022/04/16
Product BA2429777616421529612020/04/210012020/04/22
Product BA2429777616421529612020/04/210012020/04/21
Product BA2429777616421529612020/03/020012020/03/03
Product BA2429777616421529612020/03/020012020/03/02
Product BB9299997834807889162021/05/311102021/06/01
Product BB9299997834807889162021/05/311102021/05/31
Product BB9299997834807889162021/04/081102021/04/09
Product BB9299997834807889162021/04/081102021/04/08
Product BD9325858289369117192023/09/100002023/09/11
Product BD9325858289369117192023/09/100002023/09/10
Product BD9325858289369117192023/02/221102023/02/23
Product BD9325858289369117192023/02/221102023/02/22
Product BC9327780670303793862022/07/100012022/07/11
Product BC9327780670303793862022/07/100012022/07/10
Product BC9327780670303793862022/04/140112022/04/15
Product BC9327780670303793862022/04/140112022/04/14
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi  itsmeanuj ,

     

    Here are the steps you can follow:

    1. Create measure.

    Measure =
    var _maxdatecreateon=
    MAXX(
        FILTER(ALLSELECTED('Table'),
        'Table'[PRODUCT_NAME]=MAX('Table'[PRODUCT_NAME])&&'Table'[ID]=MAX('Table'[ID])),[CHANGED_ON])
    var _maxstamp=
    MAXX(
        FILTER(ALLSELECTED('Table'),     'Table'[PRODUCT_NAME]=MAX('Table'[PRODUCT_NAME])&&'Table'[ID]=MAX('Table'[ID])&&'Table'[CHANGED_ON]=_maxdatecreateon),'Table'[STAMP])
    return
    MAXX(
        FILTER(ALL('Table'),    'Table'[PRODUCT_NAME]=MAX('Table'[PRODUCT_NAME])&&'Table'[ID]=MAX('Table'[ID])&&'Table'[CHANGED_ON]=_maxdatecreateon&&'Table'[STAMP]=_maxstamp),'Table'[CALL_FLAG])
    count of IDs =
    CALCULATE(
        DISTINCTCOUNT(
        'Table'[ID]),FILTER(ALL('Table'),'Table'[PRODUCT_NAME]=MAX('Table'[PRODUCT_NAME])))

    2. Result:

     

    Best Regards,

    Liu Yang

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

3 Replies

    • itsmeanuj's avatar
      itsmeanuj
      Helper IV

      amitchandak - Thanks for your response. But in my scenario, we first need to take latest "changed_on" date and then latest "Stamp" date in that "Changed_on" date. Also this needs to be dynamic as there is a "changed_on" date slicer at the top of the page.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  itsmeanuj ,

     

    Here are the steps you can follow:

    1. Create measure.

    Measure =
    var _maxdatecreateon=
    MAXX(
        FILTER(ALLSELECTED('Table'),
        'Table'[PRODUCT_NAME]=MAX('Table'[PRODUCT_NAME])&&'Table'[ID]=MAX('Table'[ID])),[CHANGED_ON])
    var _maxstamp=
    MAXX(
        FILTER(ALLSELECTED('Table'),     'Table'[PRODUCT_NAME]=MAX('Table'[PRODUCT_NAME])&&'Table'[ID]=MAX('Table'[ID])&&'Table'[CHANGED_ON]=_maxdatecreateon),'Table'[STAMP])
    return
    MAXX(
        FILTER(ALL('Table'),    'Table'[PRODUCT_NAME]=MAX('Table'[PRODUCT_NAME])&&'Table'[ID]=MAX('Table'[ID])&&'Table'[CHANGED_ON]=_maxdatecreateon&&'Table'[STAMP]=_maxstamp),'Table'[CALL_FLAG])
    count of IDs =
    CALCULATE(
        DISTINCTCOUNT(
        'Table'[ID]),FILTER(ALL('Table'),'Table'[PRODUCT_NAME]=MAX('Table'[PRODUCT_NAME])))

    2. Result:

     

    Best Regards,

    Liu Yang

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