web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

Average Function can not be used with an empty table

(0) ShareShare
ReportReport
Posted on by 73
Hey all,
 
So i have two galleries, one (gallery_auto) is automatically gets the numbers from another gallery on another screen, and takes the average and max of the numbers and shows in a control, the second is (gallery_manual) is showing "0" as default values and lets the user enters the numbers manually if they wanted to. so i use 2 for all functions with if clauses whether to save which one. here is my for all and pathc functions;
 
IfError(
Patch(
    Articles,
    Defaults(Articles),
    {
        Article_ID: ArticleParentID_Var,
        Volume_Parent_LookUp_ID: If(
            VolumeSource_Var = "New",
            VolumeParentGuid_Var,
            Volumes_Gallery.Selected.Volume_ID
        ),
        Comm_RFQ_Lookup_ID: If(VolumeSource_Var="Edit", Project_GUID_Var, GUID(Project_Gallery.Selected.CommRFQ_ID)),
        Designation: TextInput15_2.Text,
        Hutchinson_Article_Reference: TextInput15_6.Text,
        Customer_Production_Zone: TextInput15_7.Text,
        Customer_Weekly_Article_Capacity: TextInput15_8.Text,
        Hutchinson_Production_Zone: Text(DropdownCanvas8_3.Selected.Value),
        Hutchinson_Plant: DropdownCanvas7_8.Selected.Value,
        Article_Target_Price: Value(TextInput15_9.Text),
        Customer_Reference_Number: TextInput15_3.Text,
        Mounting_Area: TextInput2.Text,
        Tool_Target_Price: Value(TextInput15_10.Text),
        Article_Comments: RichTextEditor2_11.HtmlText,

        Articles_Average_QTTY: 
        If(
            ArticleGalleryManual_Var=false, 
            Average(
            GalleryArticlesNew_Auto.AllItems,
            Value(QtyVehicules_3.Text)),
            Average(
            GalleryArticlesNew_Manual.AllItems,
            Value(QtyVehicules_4.Text))
        ),

        Articles_Max_QTTY: If(
            ArticleGalleryManual_Var=false, 
            Max(
            GalleryArticlesNew_Auto.AllItems,
            Value(QtyVehicules_3.Text)),
            Max(
            GalleryArticlesNew_Manual.AllItems,
            Value(QtyVehicules_4.Text))
        ),
        Articles_CreatedBy:User().FullName,Articles_CreatedOn:Now()
    }
),Blank());
If(
            ArticleGalleryManual_Var=false,
ForAll(
    GalleryArticlesNew_Auto.AllItems,
    Patch(
        Article_Volumes,
        Defaults(Article_Volumes),
        {
            Article_Volume_ID: GUID(),
            Article_Parent_LookUp_ID: ArticleParentID_Var,
            Comm_RFQ_Lookup_ID: Project_GUID_Var,
            Article_Volume_Volume: Value(QtyVehicules_3.Text),
            Article_Volume_Year: Value(ThisRecord.Title12_1.Text),
            Article_Volume_QTTY_Per_Vehicle: Value(QtyPerVehicules.Text),
            Article_Volume_EdittedOn: Now(),
            /*Volume_Parent_LookUp_ID: If(
                VolumeSource_Var = "New",
                VolumeParentGuid_Var,
                Volumes_Gallery.Selected.Volume_ID
            ),*/
            Volume_Parent_LookUp_ID: If(
                VolumeSource_Var = "Edit",
                VolumeParentGuid_Var,
                Volumes_Gallery.Selected.Volume_ID
            ),
            Article_CreatedBy:User().FullName,
            Article_CreatedOn:Now()
        }
    )
),
ForAll(
    GalleryArticlesNew_Manual.AllItems,
    Patch(
        Article_Volumes,
        Defaults(Article_Volumes),
        {
            Article_Volume_ID: GUID(),
            Article_Parent_LookUp_ID: ArticleParentID_Var,
            Comm_RFQ_Lookup_ID: Project_GUID_Var,
            Article_Volume_Volume:Value(ThisRecord.QtyVehicules_4.Text),
            Article_Volume_Year: Value(ThisRecord.Title12_4.Text),
            Article_Volume_EdittedOn: Now(),
            Volume_Parent_LookUp_ID: If(
                VolumeSource_Var = "Edit",
                VolumeParentGuid_Var,
                Volumes_Gallery.Selected.Volume_ID
            ),
            /*Volume_Parent_LookUp_ID: If(
                VolumeSource_Var = "New",// make it "Edit" and try if according to modified volumes_volume the new articles are saving!
                VolumeParentGuid_Var,
                Volumes_Gallery.Selected.Volume_ID
            ),*/
            Article_CreatedBy:User().FullName,
            Article_CreatedOn:Now()
        }
    )
));
when i create a new record it works fine but the error occurs when i select an existing record already saved before, and I add a new record, as sson as I come to the page, the error triggers and if i ignore it and continue to fill the necessary input controls and save it, this time i recieve 
Comm_RFQ_Lookup_ID is missing error.
 
You should be able to see that i store the lookup id in a variable and use it for this.
 
now it is not saving to the SQL Server database and not showing in the associated gallery in the app. 
 
if it is very complicated, please ask, i will be more than happy to provide more intel about the app and the formulas.  I can not overcome this error and it is breaking all the app and logic.
 
Thanks
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 714 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 419 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 243

Last 30 days Overall leaderboard