Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
gco
Resolver II
Resolver II

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

1 ACCEPTED SOLUTION
Nathaniel_C
Community Champion
Community Champion

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


new val.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

10 REPLIES 10
Nathaniel_C
Community Champion
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

new val.PNG

 



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] ) )

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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
Community Champion
Community Champion

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @Nathaniel_C 

 

Yes the calendar date is always sequential and in the calendar order.

Thank you again

 

Glen

Hi @Nathaniel_C ,

 

I just do a cast whenever i pull the date into powerbi.

 

cast (cast (ProcessDate as char(8)) as date) as ProcessDate.  

 

Please let me know if that works.  But basically, the format would be mm/dd/YYYY

Thank you again

 

Glen

Sorry, the format is YYYY-MM-DD, and then i just change it to MM/dd/YYYY in PowerBI.

Nathaniel_C
Community Champion
Community Champion

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


new val.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @Nathaniel_C 

 

Your measure worked perfectly! I am not sure how you guys come up with all these answers.  I am very interested to know how you guys learned all these tricks.

 

Thank you again.

Glen

Nathaniel_C
Community Champion
Community Champion

Thank you Glen for the kind words, you are welcome! 
What books have you read?
Nathaniel.
I can recommend two depending on what level you are at right now. @MattAllington Supercharge Power BI and @KenPuls M is for (Data) Monkey.  Look for patterns and use variables a lot.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @Nathaniel_C ,

 

I have not formally read any books.  But i went to Microsoft free powerbi trainings.

 

Most of the work i do is on the SQL side, so i tend to design my query so that i don't pull a lot of data into the report.  But most of my calculations are done within powerbi so that it does not slow down my query.  Most of the measures i currently use on all my reports are just repeats of past reports - with some additional features added.  And most of what i need i am able to figure out - just simple dax (based on what i know in SQL, i just try to translate it into dax).  And most of it come from the forums and community.  But i would look at the reference you mentioned and also try to use variables on my future projects.

 

Thanks again

Glen

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors