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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Logical problem Groupi...
Power Apps
Answered

Logical problem Grouping table

(0) ShareShare
ReportReport
Posted on by 648

Hell o put there 
If I have a table named "Glass" with the columns:

  • GlassID containing 100 records ID

    • 2 = 40 items
    • 4 = 30 items
    • 6 = 20 items
    • 8 = 10 items
  • A column named "created" with different dates and times for all records

  • A column named "Glasssnamn" containing 4 different types of ice cream:

    • Soft serve ice cream = 10 items
    • Ice cream on a stick = 20 items
    • Ice cream scoops = 30 items
    • Cheese flavored ice cream = 40 items

Then, in PowerApps, I want to create a collection grouped by GlassID that is filterable. Also, I want to see the distribution of the different ice creams in the table and be able to sort them.

For example, GlassID = 2 has Soft serve ice cream = 10 items, Ice cream on a stick = 20 items, Ice cream scoops = 30 items, and Cheese flavored ice cream = 40 items out of its 40 total items.

This is my code 

ClearCollect(
GlassCollection;
{ GlassID: 2; Glassnamn: "Mjukglass"; Antal: 10 };
{ GlassID: 2; Glassnamn: "Isglass"; Antal: 20 };
{ GlassID: 2; Glassnamn: "Kulglass"; Antal: 30 };
{ GlassID: 2; Glassnamn: "Formage"; Antal: 40 };
{ GlassID: 4; Glassnamn: "Mjukglass"; Antal: 10 };
{ GlassID: 4; Glassnamn: "Isglass"; Antal: 20 };
{ GlassID: 4; Glassnamn: "Kulglass"; Antal: 30 };
{ GlassID: 4; Glassnamn: "Formage"; Antal: 40 };
{ GlassID: 6; Glassnamn: "Mjukglass"; Antal: 10 };
{ GlassID: 6; Glassnamn: "Isglass"; Antal: 20 };
{ GlassID: 6; Glassnamn: "Kulglass"; Antal: 30 };
{ GlassID: 6; Glassnamn: "Formage"; Antal: 40 };
{ GlassID: 8; Glassnamn: "Mjukglass"; Antal: 10 };
{ GlassID: 8; Glassnamn: "Isglass"; Antal: 20 };
{ GlassID: 8; Glassnamn: "Kulglass"; Antal: 30 };
{ GlassID: 8; Glassnamn: "Formage"; Antal: 40 }
)

;;ClearCollect(
GroupedGlassCollection;
GroupBy(
GlassCollection;
"GlassID";
"GroupedGlass"
)
)

;;ForAll(
GroupedGlassCollection;
{
UpdateContext({ MjukglassAntal: LookUp(GroupedGlassCollection; GlassID = ThisRecord.GlassID && Glassnamn = "Mjukglass"; Antal; 0) });
UpdateContext({ IsglassAntal: LookUp(GroupedGlassCollection; GlassID = ThisRecord.GlassID && Glassnamn = "Isglass"; Antal; 0) });
UpdateContext({ KulglassAntal: LookUp(GroupedGlassCollection; GlassID = ThisRecord.GlassID && Glassnamn = "Kulglass"; Antal; 0) });
UpdateContext({ FormageAntal: LookUp(GroupedGlassCollection; GlassID = ThisRecord.GlassID && Glassnamn = "Formage"; Antal; 0) });
UpdateContext({ TotalAntal: Sum(ThisRecord.GroupedGlass.Antal) });
UpdateIf(
GroupedGlassCollection;
GlassID = ThisRecord.GlassID;
{
Mjukglass: MjukglassAntal;
Isglass: IsglassAntal;
Kulglass: KulglassAntal;
Formage: FormageAntal;
TotalAntal: TotalAntal
}
)
}
)

 

 

dalacarelia_196_0-1711433535371.png

 

Powerapps says no parentes use colon instead . 
Any idea how to solve this matter 


Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    153,079 Most Valuable Professional on at

    Hi @dalacarelia_196 ,

    The error is actually something quite different - you cannot set a Variable inside a ForAll statement.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • dalacarelia_196 Profile Picture
    648 on at

    Any idea how to solve this , its in the same area of what i looking for . 

    I want to display in the table all 'Klass_Elev' with each 'Title' summarized per
    'Kontrakt'; CountIf(GroupedLoggadeAPLelever[@GroupedBesokstyp]; Besokstyp = 'Kontrakt');
    Down to ToT .


    I realize that it's failing in the grouping, but I can't come up with the solution."

     

    My code is below 

    // This code collects data and groups it by "Klass_Elev".
    // For each group of "Klass_Elev", it adds a column titled "Title",
    // retrieving each title separately from each group.


    ClearCollect(
    GroupedLoggadeAPLelever;

    // Save the grouped data in a collection named GroupedLoggadeAPLelever
    AddColumns(

    // Add columns to the grouped data
    GroupBy(

    // Group the data by a specified column ("Klass_Elev") and an associated grouped column ("GroupedBesokstyp")
    YGLoggat;

    // The data source to be grouped
    "Klass_Elev";

    // The column to be grouped by
    "GroupedBesokstyp"

    // The name of the newly grouped column
    );
    "Title"; GroupedBesokstyp.Title

    // Add a column titled "Title" and retrieve each unique title separately for each group of "Klass_Elev"
    )
    );

    // This code counts the occurrences of different visit types for each group of "Klass_Elev".
    ClearCollect(
    RaknaYGLoggat;

    // Save the counted data in a collection named RaknaYGLoggat
    AddColumns(

    // Add columns to the grouped data
    GroupedLoggadeAPLelever;

    // Use the previously created grouped data as the base
    "Kontrakt"; CountIf(GroupedLoggadeAPLelever[@GroupedBesokstyp]; Besokstyp = "Kontrakt");

    // Count the occurrences of "Kontrakt" for each group of "Klass_Elev"
    "3-Partsamtal"; CountIf(GroupedLoggadeAPLelever[@GroupedBesokstyp]; Besokstyp = "3-Partsamtal");

    // Count the occurrences of "3-Partsamtal" for each group of "Klass_Elev"
    "APL besök"; CountIf(GroupedLoggadeAPLelever[@GroupedBesokstyp]; Besokstyp = "APL besök");

    // Count the occurrences of "APL besök" for each group of "Klass_Elev"
    "Bombesök"; CountIf(GroupedLoggadeAPLelever[@GroupedBesokstyp]; Besokstyp = "Bombesök");

    // Count the occurrences of "Bombesök" for each group of "Klass_Elev"
    "Telefon"; CountIf(GroupedLoggadeAPLelever[@GroupedBesokstyp]; Besokstyp = "Telefon");

    // Count the occurrences of "Telefon" for each group of "Klass_Elev"
    "ToT"; CountIf(GroupedLoggadeAPLelever[@GroupedBesokstyp]; Besokstyp = "Kontrakt" || Besokstyp = "Telefon" || Besokstyp = "3-Partsamtal" || Besokstyp = "APL besök" || Besokstyp = "Bombesök")

    // Count the total occurrences of specified visit types for each group of "Klass_Elev"
    )
    )

    The outcone in excel this is what i need to solve

     

    dalacarelia_196_0-1711443607139.png

     

  • Verified answer
    dalacarelia_196 Profile Picture
    648 on at

    Finaly i was able to solve my issue 

    ;;ClearCollect(
    VisaListanGrupperad;
    AddColumns(
    SortByColumns(
    Filter(
    KoppladeAPLelever;
    Klass_Elev in ComboKLassval.SelectedItems.Result ;Elev =BesoksplanGallery.Selected.Elev
    );
    "Created";
    SortOrder.Descending;
    "Elev";
    SortOrder.Ascending
    );
    "YGLoggatRowCount";
    CountRows(
    Filter(
    YGLoggat;
    Title = Elev
    )
    );
    "Besokstyp";
    Last(
    Filter(
    YGLoggat;
    Title = Elev
    )
    ).Besokstyp;

     

    "3Part";CountRows(Filter(YGLoggat; Title = Elev; Besokstyp ="3-Partsamtal"));
    "Telefon"; CountRows(Filter(YGLoggat; Title = Elev; Besokstyp ="Telefon"));
    "APL-Besök";CountRows(Filter(YGLoggat; Title = Elev; Besokstyp ="APL-Besök"));
    "Bombesök";CountRows(Filter(YGLoggat; Title = Elev; Besokstyp ="Bombesök"));
    "Kontrakt";CountRows(Filter(YGLoggat; Title = Elev; Besokstyp ="Kontrakt"));

     

    "SenasteBesoksdatum";
    Last(
    Filter(
    YGLoggat;
    Title = Elev
    )
    ).Created
    )
    )

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard