I want to show display units based on values in graphs. Like If value > 1000 then in Thousands ex:'5K', if value > 1000000 then in Millions ex: '5M', if value is < 1000 then value itself ex: 500.
First the problem depends on where you want to display the value. Most visualizations offer a Display format option which can be set to auto to do the trick. It chooses one scale and puts all values on this scale. This makes sense as a bar chart compaing values in millions to values in hundreds hardly adds any visualiztion value as the diffirence is too big (unless using a logarithmic scale of course). For most occasions that will do the job just fine.
So let's assume a case in which you need to compare really large and small values. You can create a measure to change the formatting based on the size of the value. One major downside is that the value is converted to text and can no longer be aggregated as a value in a visual requiring that. You can still use it in a table or as tooltip in bar chart for instance as those fields de accept text values. In this case make sure the aggregating expression is evaluated before the conversion to text to match the context in your visual. I've done this by placing the calculation in a seperate variable which can also reference another measure.
Measure =
var calc = SUM ( 'Values'[Value] ) // could be any calculation or reference to other measure
var decimals = "0.0"
RETURN
SWITCH ( TRUE() ;
calc > 1000000 ; FORMAT ( calc / 1000000 ; decimals & "M" ) ;
calc > 1000 ; FORMAT ( calc / 1000 ; decimals & "K" ) ;
FORMAT ( calc ; decimals )
)