Forum Discussion

penningmic's avatar
penningmic
Frequent Visitor
5 years ago
Solved

Get value for specific data from measure then categorize

Hello,  I have a dataset where I previously adapted code from my following question: lastnonblank - relating 2 tables via measure to get value Producing an output like this (Example, not synced w...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi penningmic ,

     

    According to my understanding, you want to get the change between the first and the last value of each Item and calculate the number of items under each value change, right?

     

    You could try this to add a column to DataTable:

    Type =
    VAR _mindate =
        CALCULATE (
            MIN ( 'DataTable'[Created Date] ),
            ALLEXCEPT ( 'DataTable', 'DataTable'[Item_Num] )
        )
    VAR _fir =
        MINX (
            FILTER (
                'DataTable',
                'DataTable'[Item_Num] = EARLIER ( 'DataTable'[Item_Num] )
                    && 'DataTable'[Created Date] = _mindate
            ),
            [Value]
        )
    VAR _maxdate =
        CALCULATE (
            MAX ( 'DataTable'[Created Date] ),
            ALLEXCEPT ( 'DataTable', 'DataTable'[Item_Num] )
        )
    VAR _last =
        MAXX (
            FILTER (
                'DataTable',
                'DataTable'[Item_Num] = EARLIER ( 'DataTable'[Item_Num] )
                    && 'DataTable'[Created Date] = _maxdate
            ),
            [Value]
        )
    RETURN
        _fir & " to " & _last
    

    The final output is shown below:

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