Forum Discussion

GouldM's avatar
GouldM
Regular Visitor
1 year ago
Solved

Comparing to a 'Previous Category'

Supposing I have data in this table Category   Value 1                3 2                6 3                7   How could I create a measure that DIVIDEs the value of a category but the value o...
  • bhanu_gautam's avatar
    1 year ago

    GouldM , Create a measure using

    DAX
    Comparator =
    VAR CurrentCategory = 'Table'[Category]
    VAR PreviousCategoryValue =
    CALCULATE(
    MAX('Table'[Value]),
    FILTER(
    'Table',
    'Table'[Category] = CurrentCategory - 1
    )
    )
    RETURN
    IF(
    ISBLANK(PreviousCategoryValue),
    BLANK(),
    DIVIDE('Table'[Value], PreviousCategoryValue)
    )

  • ryan_mayu's avatar
    ryan_mayu
    1 year ago

    GouldM 

    you can try this to create a column

     

    Column =
    var _last=maxx(FILTER('Table','Table'[category]=EARLIER('Table'[category])-1),'Table'[value])
    return if(ISBLANK(_last),blank(),DIVIDE('Table'[value],_last))
    or try this to create a measure
     
    Measure =
    var _last=maxx(FILTER(all('Table'),'Table'[category]=max('Table'[category])-1),'Table'[value])
    return if(ISBLANK(_last),blank(),DIVIDE(max('Table'[value]),_last))
    pls see the attachment below