Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Inspect records in Group By table for values and return conditional value based on result

Once you perform a group by on a table and have a new column that holds all the aggregated data as a table object, is it possible to inspect the contents of that aggregated data, do some if/then logic, and return a value in a new column based on the results?  At first I was looking at a few custom columns, but I couldn't figure out the right logic for that column definition to make it dig into the grouped data once I group by PC Name.
 
I have a small sample example below.  Essentially I have a messy table of all software installed across PC's.  I'm trying to find which machines have some version of "ArcGIS Desktop" installed, and which have "ArcGIS Pro" installed. 
 
PC Name Application BUILD OS Application Category Version
KVWLKArcGIS Desktop 10.6.110.6.9270Windows 7Desktop10.6.1
PRWTVArcGIS 10.4.1 for Desktop10.4.5686Windows 10Desktop10.4.1
KVWLKArcGIS Pro2.4.19948Windows 7Pronull
BLTORArcGIS Pro2.5.22081Windows 10Pronull
GRMTPArcGIS Desktop 10.5.110.5.7333Windows 10Desktop10.5.1
PRWTVArcGIS Workflow Manager 10.4.1 for Desktop10.4.7146Windows 10Other10.4.1
PRWTVArcGIS Data Reviewer 10.4.1 for Desktop10.4.862Windows 10Other10.4.1
 
And  the result I want is this:
PC Name OS ArcGIS Desktop Version ArcGIS Desktop Build ArcGIS Pro Version ArcGIS Pro Build Other Installs
KVWLKWindows 710.6.110.6.92702.42.4.19948null
GRMTPWindows 1010.5.110.5.7333Not InstalledNot Installednull
BLTORWindows 10Not InstalledNot Installed2.52.5.22081null
PRWTVWindows 1010.4.110.4.5686Not InstalledNot InstalledArcGIS Workflow Manager 10.5.1 for Desktop
ArcGIS Workflow Manager 10.5.1 for Desktop
 
 
 
In pseudo code here's what I'm trying to do:
For each PC:
 Create Column for ArcMap Version
  Loop through aggregated data for this row
   If row WHERE "Application Category" = "Desktop"
    THEN return "Version" value from the aggregated row
 Create Column for Pro Version
  Loop through aggregated data for this row
   If row WHERE "Application Category" = "Pro"
    THEN return "Version" value from the aggregated row
 Create Colomn for Other Software
  Loop through aggregated data for this row
   For each row WHERE "Application Category" = "Other"
    concatenate values together and return
 
Any help would be appreciation,  
 
-Andrew
1 ACCEPTED SOLUTION
artemus
Employee
Employee

This is pretty simple, assuming your table column is "Grouped Rows" your custom column for ArcMap Version would be:

= [Grouped Rows]{[Application Category = "Desktop"}]?[Version]?

 

Note: Will give error if sub table has multiple Application Categories with the same value.

View solution in original post

3 REPLIES 3
artemus
Employee
Employee

This is pretty simple, assuming your table column is "Grouped Rows" your custom column for ArcMap Version would be:

= [Grouped Rows]{[Application Category = "Desktop"}]?[Version]?

 

Note: Will give error if sub table has multiple Application Categories with the same value.

Anonymous
Not applicable

This ended up working for me..or at least got me close enough to understand the logic of the curly brackets.  Just to clarify, below is the syntax that worked for me:

 

Adding the "ArcMap Version" column that holds the version or build value from the table object:

ArcMap Version = try [data]{[Application Category = "Desktop"]}[Version]
otherwise "None"

 

Adding the "Other Version" column to store a list of all the other software:

Step 1:  Add custom column that holds a list of the values with this formula: = Table.AddColumn(#"Added Custom3", "Other GIS Intalls", each Table.ToList(Table.SelectColumns(Table.SelectRows([data],each [Application Category] = "Other"),{"Application"})))

 

Step 2:  Expand the list using this formula (or clicking the expand button on the list's column header in the GUI:

= Table.TransformColumns(#"Added Custom4", {"Other GIS Intalls", each Text.Combine(List.Transform(_, Text.From), "#(cr)"), type text})

 

-Andrew

Anonymous
Not applicable

the final goal is not completely clear to me, but let try to use this scheme (is substantially a group by inside another group By)

 

 

 

    rr= Table.Group(yourTab, {"PC"},  {"cat", each Table.Group(_,{"Application Category"},{"dpo", (pc)=> pc[Application]})}),
    te= Table.ExpandTableColumn(rr, "cat", {"Application Category", "dpo"}, {"cat.Application Category", "cat.dpo"}),
    ve = Table.TransformColumns(te, {"cat.dpo", each Text.Combine(List.Transform(_, Text.From), ","), type text})
in
    ve

 

You obviously have to adapt and complete the code.
Let me know if you find it suitable and sufficient to continue your analysis.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors