Forum Discussion

Kella's avatar
Kella
Frequent Visitor
3 years ago
Solved

DAX measure

Hi, How to I create a measure with Week Index for requirement below? Thanks ya'll in advance!   Example; Table Apple; Product Group      Week1   Week2   Week3 AA      2   1   6 BB ...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Kella ,

    I have created a simple sample, please refer to my pbix file to see if it helps you.

    Create measures.

    Measure =
    RANKX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Product Group] = SELECTEDVALUE ( 'Table'[Product Group] )
        ),
        CALCULATE ( MAX ( 'Table'[week] ) ),
        ,
        ASC
    )
    
    Measure2 =
    VAR _1 =
        SELECTEDVALUE ( 'week slicer'[week ] )
    VAR _2 =
        RANKX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Product Group] = SELECTEDVALUE ( 'Table'[Product Group] )
            ),
            CALCULATE ( [Measure] ),
            ,
            ASC
        )
    VAR _rankxpro =
        RANKX (
            ALL ( 'Table' ),
            CALCULATE ( MAX ( 'Table'[Product Group] ) ),
            ,
            ASC,
            DENSE
        )
    VAR _value =
        IF ( _1 = [Measure] && _rankxpro = 1, MAX ( 'Table'[Value] ), BLANK () )
    RETURN
        _value
    

     

    Measure3 =
    VAR _rankxpro =
        RANKX (
            ALL ( 'Table' ),
            CALCULATE ( MAX ( 'Table'[Product Group] ) ),
            ,
            ASC,
            DENSE
        )
    VAR _1 =
        MAXX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Product Group] = SELECTEDVALUE ( 'Table'[Product Group] )
            ),
            [Measure2]
        )
    VAR _all =
        MAXX ( ALL ( 'Table' ), [Measure2] )
    VAR _3 =
        IF ( _1 = BLANK (), _rankxpro + _all - 1, _1 )
    RETURN
        ( MAX ( 'Table'[Value] ) / _3 ) * 100
    

     

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Rongtie

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