Using Model_lookup with Ui-only field - can't make it work

  • 2
  • Question
  • Updated 2 years ago
I've managed to get Ui-only formula fields to work using aggregations within the same model, but am having trouble pulling in a number from a different model.

My goal is to show an an average, by dividing a count from one model by a distinct count from another. I think I should be able to do this with a model_lookup in a Ui-only formula field. 

Here's what I have, please let me know if there's something I am doing wrong, or if I'm running into the limitations of Skuid/salesforce.

Thanks in advance for any help!

Photo of Josh Merritt

Josh Merritt

  • 918 Points 500 badge 2x thumb

Posted 3 years ago

  • 2
Photo of Mansour

Mansour

  • 1,932 Points 1k badge 2x thumb
On the Cancellations aggregate model, can you try giving it an aggregate function (e.g. AVG of AvgCancel...).
If that doesn't work, try re-querying the MonthlyActiveClients model when the page loads (you can do this with a tab initial load action for example).
Lastly, if that doesn't work, try wrapping your formula in VALUE(xxxx) functions.  It should be VALUE(xxx)/VALUE(MODEL_LOOKUP(xxx)).
Photo of Josh Merritt

Josh Merritt

  • 918 Points 500 badge 2x thumb
Thanks, Mansour. 

I think the problem lies in my model_lookup formula. I tried wrapping both parts in VALUE() functions but it's still not returning anything.

Aggregating the field at the chart level did not work and querying the model on page load did not seem to do anything either.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
I have a suspicion that your UI only field is not actually getting populated.   Put that field in a template, or build a table to see if you are actually getting values. 
I think your model lookup function is returning a string,  which is not working in your divide by calculation.  You might wrap the model lookup section in a "Value()" Function. 
Photo of Josh Merritt

Josh Merritt

  • 918 Points 500 badge 2x thumb
Thanks, Rob.

I tried wrapping the formula with VALUE() functions:

VALUE({{TotalCancelsByMonth}}) / VALUE(MODEL_LOOKUP("MonthlyActiveClients","countdistinctCoaches","cmSnapshotDatec",{{cmEndDatec}}))

But it still won't return anything. I'm not sure if I'm using the model_lookup function correctly. I think the first two arguments are correct, but I'm not sure about the last two. Both models are grouping data at the calendar month level. 
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Here is a little help on the four arguments of the model lookup formula. 
Arg 1:  Model ID of what you are looking up against. 
Arg 2:  Field id of the value that you want to return into your UI only field.  (in this case - in an aggregate model, you use the alias fieldname) 
Arg 3: Field id in the Model from Arg 1 that is used to match against. 
Note - Arguments 1 - 3 need to be in quotes. 
Arg 4: Field from the model you are building the UI Only model on that you want to pass over in order to retrieve.  This argment is usually in our merge syntax. 

So... this is what you are telling skuid to do:  Retrieve the count of coaches from the MonthlyActiveClients model when the SnapshotDate month  is the same as the EndDate month from the current model. 

Does that make sense? 
Photo of Josh Merritt

Josh Merritt

  • 918 Points 500 badge 2x thumb
Thanks for the detailed explanation!

That makes sense to me. However, it's perplexing, because I think I've set up my model_lookup correctly. 

I think the issue must be in the Arg 4, because I don't see any room for error in the first 3. Can you explain more "This argment is usually in our merge syntax" statement? 
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Josh, What is cmEndDatec?

It may be that you're passing a date that doesn't exactly match.
Photo of Mansour

Mansour

  • 1,932 Points 1k badge 2x thumb
This is silly, but I think I found a way to make it work.
Create a new UI-Only field that shows the value of your close date in a number format.  Do that for both fields in the models you are connecting via the MODEL_LOOKUP function.  Then, when writing the formula, use the Values to connect the two instead of the actual fields.

Screenshots below may help.


Photo of Josh Merritt

Josh Merritt

  • 918 Points 500 badge 2x thumb
THANK YOU!

It works flawlessly. I appreciate the creative solution. Had you run into a similar issue? Wondering if this is an isolated problem with dates and date functions. 

Thanks to all three of you for helping solve this problem. 
(Edited)
Photo of Mansour

Mansour

  • 1,932 Points 1k badge 2x thumb
Ran into it this morning, which made me think of your post.  It seems to be specific to aggregate models.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Kudos to Mansour.  I think we're going to have to crown him as king of the formula fields. 
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
This post was very helpful. Thank you to all who contributed!
Photo of Bill Fox

Bill Fox

  • 7,954 Points 5k badge 2x thumb
I am sure I have something in the wrong order?

The UI-field is on the LeadPerson Model and I am trying to pull information in from Entity_Person.  I have the Entiry_Person loading first. 

Here is what I have in a formula field returning text:

MODEL_LOOKUP("Entity_Person","View_Person__c",
"Entity_ID__c",
{{Lead_Referring_Entity_ID__c}})


Thanks in advance,
Bill