Forum

Is there anything l...
 
Notifications
Clear all

Is there anything like Min/Max for numbers in PQ

4 Posts
3 Users
0 Reactions
93 Views
(@raista)
Posts: 5
Active Member
Topic starter
 

Hi,

currently I'm looking how to manage something like 'truncate a text (<txt>) by 1 character of it's length', which in general is pretty easy with

Text.Start(<txt>, Text.Length(<txt>)-1)

But I want to make shure, that this will not generate an error in case the <txt> is empty. Therefore I'd like to write something like

Text.Start(<txt>, MAX(0,Text.Length(<txt>)-1))

Any idea? Thanks!

RaiSta

 
Posted : 28/06/2022 3:33 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi RaiSta,

You could try

if Text.Length(<txt>) > 0 then Text.Start(<txt>, MAX(0,Text.Length(<txt>)-1)) else null

Regards

Phil

 
Posted : 28/06/2022 6:13 pm
(@debaser)
Posts: 836
Member Moderator
 

You could also do something like:

Text.Start(<txt>, List.Max({0,Text.Length(<txt>)-1})))

 

Just bear in mind that you are likely to end up with a mix of empty text and null values in the resulting column.

 
Posted : 29/06/2022 4:20 am
(@raista)
Posts: 5
Active Member
Topic starter
 

Thanks Philip, thanks Velouria,

both answers seem to fulfil my needs, but I can mark only one to be an ('the') answer... so I took the first.

Will see, as soon as I'm back to the topic of interest how it works in 'free nature' - but this could take some time. And I will not set it to 'null', but to the original text, because only 'truncatable' texts will be modified. This will be just a safety issue, to cover rare cases outside my test environments, that the query will not throw an error which might not be able to be handled from persons using my design. You know: it works well in all tested cases and 99.xxx% of all applications. But after long time of working all of a sudden an 'unexplainable' error shows up, me maybe no longer at hand or whatever else. Just to be prepared...

Thanks for your contributions,

RaiSta

 
Posted : 29/06/2022 4:34 pm
Share: