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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jackofalltrades
Frequent Visitor

SQL Statement to Dynamically Use Max Value in a Column

I have a date column in my data, but the format and data type is not a date. The format is 01220102 which is January 02, 2022. I want to right a SQL statement in the adavanced options that will pull records that are the maximum value - X. For example, only return records ColumnX >= (Max(ColumnX)-200).

 

Any help is appreciated!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jackofalltrades ,

Are you connecting to the sql data source on the desktop? If so, you can try to use dax.

Create a measure.

Measure=VAR _MAXVALUE=MAXX(ALL(TABLE),ColumnX)
VAR _MAX200=_MAXVALUE-200
return
IF(MAX(ColumnX)>=_MAX200&&MAX(ColumnX)<=_MAXVALUE,1,BLANK())

Or a column. 

Column=VAR _MAXVALUE=MAXX(TABLE,ColumnX)
VAR _MAX200=_MAXVALUE-200
return
IF(ColumnX>=_MAX200&&ColumnX<=_MAXVALUE,1,BLANK())

 

If you want to use sql formula in SQL, then you need to go to the SQL forum.

 

If I have misunderstood your meaning, please provide some simple sample data without privacy information and your desired output.

 

How to Get Your Question Answered Quickly 

 

 Best Regards
Community Support Team _ Polly

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

View solution in original post

2 REPLIES 2
jackofalltrades
Frequent Visitor

I will move to the SQL forum. My apologies for posting in the wrong area. Thanks!

Anonymous
Not applicable

Hi @jackofalltrades ,

Are you connecting to the sql data source on the desktop? If so, you can try to use dax.

Create a measure.

Measure=VAR _MAXVALUE=MAXX(ALL(TABLE),ColumnX)
VAR _MAX200=_MAXVALUE-200
return
IF(MAX(ColumnX)>=_MAX200&&MAX(ColumnX)<=_MAXVALUE,1,BLANK())

Or a column. 

Column=VAR _MAXVALUE=MAXX(TABLE,ColumnX)
VAR _MAX200=_MAXVALUE-200
return
IF(ColumnX>=_MAX200&&ColumnX<=_MAXVALUE,1,BLANK())

 

If you want to use sql formula in SQL, then you need to go to the SQL forum.

 

If I have misunderstood your meaning, please provide some simple sample data without privacy information and your desired output.

 

How to Get Your Question Answered Quickly 

 

 Best Regards
Community Support Team _ Polly

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

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors