SOLVED

Referencing a NULL field - Customized Column

%3CLINGO-SUB%20id%3D%22lingo-sub-3072658%22%20slang%3D%22en-US%22%3EReferencing%20a%20NULL%20field%20-%20Customized%20Column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3072658%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20reference%20a%20null%20field%20but%20I%20am%20not%20getting%20right.%20I%20am%20trying%20to%20display%20%22%25%22%20after%20my%20calculation.%20So%20I%20have%20a%20number%20column%20called%20Budget%20Cost.%20I%20created%20a%20Text11%20column%20and%20had%20a%20customized%20formula%20in%20it.%20The%20logic%20I%20want%20is%20If%20there%20is%20a%20value%20in%20the%20Budget%20Cost%20column%20calculate%20the%20percentage%20and%20concatenate%20%22%25%22%20at%20end.%20If%20Budget%20Cost%20is%20empty%20is%20don't%20do%20anything%20leave%20it%20empty.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20formula%20in%20the%20Tex11%20column%20is%20as%20follows%3A%3C%2FP%3E%3CP%3Eformat(%5BBudget%20Cost%5D%2F186000*100%2C%22%23.00%22)%20%26amp%3B%20%22%20%25%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20something%20like%20below%3A-%3C%2FP%3E%3CP%3Eiif%20(%5BBudget%20Cost%5D%20%26lt%3B%26gt%3B%20%3F%3F%3F%3F%3F%2C%20format(%5BBudget%20Cost%5D%2F186000*100%2C%22%23.00%22)%20%26amp%3B%20%22%20%25%22%2C%20%22%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewhat%20do%20I%20put%20in%20%3F%3F%3F%3F%20...I%20have%20tried%20NULL%2C%20I%20have%20tried%20%22%22%20nothing%20works%20I%20keep%20getting%20%23ERROR%20(shown%20in%20red%20below)%20it%20just%20should%20be%20empty.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOr%20the%20above%20syntax%20is%20not%20correct.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAppreciate%20any%20help.%3C%2FP%3E%3CP%3EBest%20Rgds%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Kish27_0-1643208576523.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F342583iA0EA7BB1BCB41E5D%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Kish27_0-1643208576523.png%22%20alt%3D%22Kish27_0-1643208576523.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3072752%22%20slang%3D%22en-US%22%3ERe%3A%20Referencing%20a%20NULL%20field%20-%20Customized%20Column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3072752%22%20slang%3D%22en-US%22%3Ekish27%2C%3CBR%20%2F%3ESorry%20but%20something%20doesn't%20quite%20make%20sense.%20You%20say%20you%20have%20a%20custom%20number%20column%20called%20Budget%20Cost%2C%20but%20number%20fields%20will%20always%20have%20a%20default%20value%20of%20zero.%20Are%20you%20sure%20you%20don't%20mean%20your%20Budget%20Cost%20field%20is%20a%20custom%20Text%20field%3F%3CBR%20%2F%3E%3CBR%20%2F%3EProject%20does%20have%20a%20Budget%20Cost%20field%20but%20it%20is%20only%20applicable%20to%20the%20Project%20Summary%20Task.%3CBR%20%2F%3E%3CBR%20%2F%3EAssuming%20your%20%22Budget%20Cost%22%20field%20is%20Text2%2C%20the%20following%20formula%20should%20give%20what%20you%20want%3A%3CBR%20%2F%3EIIf(%5BText2%5D%26lt%3B%26gt%3B%22%22%2Cformat(%5BText2%5D%2F186000*100%2C%22%23.00%22)%20%26amp%3B%20%22%20%25%22%2C%22%22)%3CBR%20%2F%3E%3CBR%20%2F%3EHope%20this%20helps.%3CBR%20%2F%3EJohn%3C%2FLINGO-BODY%3E
Contributor

Hi

 

I am trying to reference a null field but I am not getting right. I am trying to display "%" after my calculation. So I have a number column called Budget Cost. I created a Text11 column and had a customized formula in it. The logic I want is If there is a value in the Budget Cost column calculate the percentage and concatenate "%" at end. If Budget Cost is empty is don't do anything leave it empty.

 

My formula in the Tex11 column is as follows:

format([Budget Cost]/186000*100,"#.00") & " %"

 

I need something like below:-

iif ([Budget Cost] <> ?????, format([Budget Cost]/186000*100,"#.00") & " %", "")

 

what do I put in ???? ...I have tried NULL, I have tried "" nothing works I keep getting #ERROR (shown in red below) it just should be empty.

 

Or the above syntax is not correct.

 

Appreciate any help.

Best Rgds

 

 

Kish27_0-1643208576523.png

 

11 Replies
best response confirmed by Kish27 (Contributor)
Solution
kish27,
Sorry but something doesn't quite make sense. You say you have a custom number column called Budget Cost, but number fields will always have a default value of zero. Are you sure you don't mean your Budget Cost field is a custom Text field?

Project does have a Budget Cost field but it is only applicable to the Project Summary Task.

Assuming your "Budget Cost" field is Text2, the following formula should give what you want:
IIf([Text2]<>"",format([Text2]/186000*100,"#.00") & " %","")

Hope this helps.
John
Kish --

Allow me to add to the excellent answer from my esteemed colleague, John. It appears you are not referencing the built-in Budget Cost column in Microsoft Project, as that field only allows you to enter a value at the Project Summary Task level (Row 0 or Task 0). In what type of field did you create this custom field? If you are using a custom Number field, then your formula would be as follows:

IIf ([Budget Cost] <> 0, format ([Budget Cost]/186000*100,"#.00") & " %", "")

If you are using a custom Text field, then you should use the formula that John offers you. Please let us know and we will try to help you.

@Dale Howard 

 

Hi

Thanks guys for responding. Looks like it is how I defined Budget Cost either as Text or Number. But when I checked Budget Cost it is not a customized column it was inserted using MS Project "Add New Column" it is already there.  So to test both yours and John's expression, I created two columns %Budget Number (which is a number column) and %Budget Text (which is a text column). Then I inserted the following expressions as formula given by you guys as follows:

 

%Budget Number I had -> IIf([Budget Cost]<>0,format([Budget Cost]/186000*100,"#.00") & " %","")

%Budget Text I had -> IIf([Budget Cost]<>"",format([Budget Cost]/186000*100,"#.00") & " %","")

 

The results as shown below:

Kish27_0-1643276397690.png

 

Looks like Budget Cost is treated as text column as the expression given by John works. If thinking Budget Cost is a number column it shows entries with #ERROR. But it got the summary level number correct.

 

One small slight issue here is with John's expression I need to tweak the format a bit to solve if numbers have a leading zero. For example if you watch the bottom portion of the output .43% and .32% should be displayed as 0.43% and 0.32% respectively.  Is there a link or documentation on how I can tweak this format of "#0.00" to something that will resolve my issue above.

 

Best Rgds

Kish

Kish27,
You actually answered your own question. Your format statement uses "#.00" as the format which of course will not provide a leading zero. But the last line of your post mentions a format of "#0.00" which WILL provide a leading zero.

One caution about using math with text fields. In this particular case it works but the compiler will not always interpret text such that a math equation can be performed.

The reason you got an error when you thought you tried Dale's method is because (according to your screen shot) the "Budget Cost" column is clearly a Text field and the formula is trying to compare that to zero, hence the error.
John

@John-project 

Hi John

Thanks for your reply. Yes indeed changing the format to #0.00 indeed was what I wanted.

 

Regarding the warning that mixing text and number calculation may sometimes give problems I guess we need to convert the number to text using some function such as cstr. Maybe below expression would be safer and better as it also works: Below converts maths part ([Budget Cost]/186000 *100) to a string. ( Budget Cost is provided by MS Project which I gather is a text field)

 

IIf([Budget Cost]<>"",format(cstr([Budget Cost]/186000*100),"#0.00") & "%","")

 

Is there a document which describes on what functions we can use in the formula ? Or can I use any Visual Basic functions in the formula in the customized field?

 

Best Rgds

Kish

Kish,
Your use of the term "budget cost" has been an issue throughout this thread. Project has a field called Budget Cost but that field is only applicable to the Project Summary task. The "Budget Cost" you use is apparently a renamed Text field (e.g. Task Text1). Project's Budget Cost field is not stored as a string, it is stored as a cost number but it IS internally reformatted and displayed as a text field when viewed by the user in the Gantt Chart view for example.

I think you misunderstood my comment about attempting to use math relationships on Project fields that are stored as text. If doing math operations on data that is stored internally as text, that data should first be converted to numerical data (e.g. Csng, Cint, etc.) before doing the math operation. If the desire is to then display the result in text form, it may or may not need to be converted to text but normally the interpreter will work directly with numerical data when displaying in text form.

Here is a link to Project functions for custom fields:
https://support.microsoft.com/en-us/office/project-functions-for-custom-fields-in-project-desktop-7e...

In many cases VBA functions will also work in custom field formulas but VBA has a much larger selection so not all VBA functions are usable in custom fields.

Previously you ask for a link for the Format function:
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/format-function-v...

John
Hi
Thanks for you reply and clarification. Appreciate the links you provided as well. I guess this thread can be considered as close.
Thank you so much for the prompt replies and responses.
Best Rgds
Kish
Kish27,
You're welcome and thanks for the feedback.
John
Hi John
I was going to tag one of your replies as the best response I noticed Dale has done so. I would like tag another response as best response but don't seem to know how to tag this. I was looking for option in the reply I cannot see how this is done. Any idea how this is done.
Rgds
Kish
Kish --

I untagged one of John's responses. Feel free to task whichever response you believe is the best answer.
Hi Dale
It was the same one you tagged. Hence Ire- tag the same response as the best answer from John. I thought each discussion thread could have more than one best response tag which is not the case. Thanks anyway for untagging and also thanks also for your responses in this discussion. Help much appreciated.
rgds
kish