Forum Discussion

gco's avatar
gco
Resolver II
6 years ago
Solved

Data manipulation

Hi there, 

 

I am trying to make a measure in PowerBI from the following data.

 

CodeProcessDateTransDateValueNewValue
120190630201906291025
120190701201907012525
120190702201907023030

 

I wanted the NewValue to become the next day's value when Processdate <> TransDate.  So in the above example, the new value for ProcessDate '20190630' is 25 based on the next day value.

 

Thank you

Glen

  • Hi gco ,

    Measure NewValue = 
    var _pDate = MAX(NVAL[ProcessDate])
    var _tDate = MAX(NVAL[TransDate])
    
    var _tValue = Calculate(MAX(NVAL[Value]), ALLEXCEPT(NVAL,NVAL[ProcessDate],NVAL[Code]),NVAL[ProcessDate]=_pDate+1)
    
    return
    IF (_pDate <> _tDate,_tValue, MAX(NVAL[Value]))


    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πŸ‘are nice too.
    Nathaniel


     

10 Replies

  • Nathaniel_C's avatar
    Nathaniel_C
    Community Champion

    Hi gco ,
    I added an Index col in Power Query.

    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πŸ‘are nice too.
    Nathaniel

     



    Measure NewValue =
    VAR _pDate =
        MAX ( NVAL[ProcessDate] )
    VAR _tDate =
        MAX ( NVAL[TransDate] )
    VAR _curIndex =
        MAX ( NVAL[Index] )
    VAR _tValue =
        CALCULATE (
            MAX ( NVAL[Value] ),
            ALLEXCEPT ( NVAL, NVAL[Index] ),
            NVAL[Index] = _curIndex + 1
        )
    RETURN
        IF ( _pDate <> _tDate, _tValue, MAX ( NVAL[Value] ) )

     

    • gco's avatar
      gco
      Resolver II

      Hi Nathaniel_C ,

       

      Thanks for the very quick response.  Your measure would have worked - I like how you came up with it.  However, i left out some details on the table.  I am pulling different codes at the same time, so it won't work if i use the index.  Is it possible to have the measure look for the next identical code?  Thank you again.

       

      CodeProcessDateTransDateValueNewValue
      120190630201906291025
      220190630201906301010
      320190630201906305050
      120190701201907012525
      420190701201907016060
      520190701201907016565
      • Nathaniel_C's avatar
        Nathaniel_C
        Community Champion

        Hi gco are the dates sequential? Can we always assume that they are in calendar order?Nathaniel