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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
pk1593
Helper I
Helper I

DAX Code Help

I have a sample data with Survey waves (from 5 different time periods 1 to 5). 

Need help in creating the below 3 columns highlighted in green. 

1. Latest Wave column: Need to create a new column in Power BI using DAX. This should be based on "Maximum" value from Survey_Wave column. If true 1 or else 0. 

2. Previous Wave column: Need to create a new column in Power BI using DAX. This should be based on "Maximum" value -1 from Survey_Wave column. If true 1 or else 0. 

3. Last 3 waves columns: Need to create a new column in Power BI using DAX. This should be based on "Top 3" value from Survey_Wave column. If true 1 or else 0. 

It is important to note that the code should be dynamic as the Survey_Wave column over time will get more values (6, 7 .... etc going forward in time)

 

Desired Result as below: 

pk1593_0-1689319270634.png

Pbix file link - Download here

 

1 ACCEPTED SOLUTION
ValtteriN
Community Champion
Community Champion

Hi, 

Here is one way to do this:

Data:

ValtteriN_0-1689322113825.png

 

Dax:

Latest =
var _max = MAX('Table (35)'[survey_wave]) return
IF('Table (35)'[survey_wave] = _max,1,0)

2. 
Latest =
var _max = MAX('Table (35)'[survey_wave])-1 return
IF('Table (35)'[survey_wave] = _max,1,0)

top 3 = 
var _max = MAX('Table (35)'[survey_wave])-2 return
IF('Table (35)'[survey_wave] >= _max,1,0)


Test (added data):
ValtteriN_1-1689322366678.png

 

End result:
ValtteriN_2-1689322391276.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/




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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
ValtteriN
Community Champion
Community Champion

Hi, 

Here is one way to do this:

Data:

ValtteriN_0-1689322113825.png

 

Dax:

Latest =
var _max = MAX('Table (35)'[survey_wave]) return
IF('Table (35)'[survey_wave] = _max,1,0)

2. 
Latest =
var _max = MAX('Table (35)'[survey_wave])-1 return
IF('Table (35)'[survey_wave] = _max,1,0)

top 3 = 
var _max = MAX('Table (35)'[survey_wave])-2 return
IF('Table (35)'[survey_wave] >= _max,1,0)


Test (added data):
ValtteriN_1-1689322366678.png

 

End result:
ValtteriN_2-1689322391276.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/




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

Proud to be a Super User!




Thank you @ValtteriN 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.