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
RobRoos
Frequent Visitor

Divide by number of rows per item

Hi,

I've got this table and want to divide Sum of DiskSizeInGB by number of same Srv-computers.

(In the source data I get, total Sum of DiskSize per server, is listed per app)

  

Srv-computerAppSum of DiskSizeInGBSizePerApp
TST033101610305
TST033102610305
TFSTS131551A12475141583.7
TFSTS131551B12475141583.7
TFSTS131551C12475141583.7
TFXTV120014J320320

 

I got this far, but get a error:

let
Source = Excel.Workbook(File.Contents(".......\Storage analysis 20220518.xlsx"), null, true),
Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
#"Added Custom" =

Table.AddColumn(Table1_Table, "SizePerApp", 

each [Sum of DiskSizeInGB]/
List.Count(List.Select(Table1_Table[#"Srv-computer"], each _ = [#"Srv-computer"])))


in
#"Added Custom"

 

Expression.Error: We cannot apply field access to the type Text.
Details:
Value=TST03310
Key=Srv-computer

 

 

Is my calculation of number of rows per Srv-computer correct?

 

Who can help me out?

Thanks in advance!

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Replace each _ = [#"Srv-computer"] with (x)=>x= [#"Srv-computer"]

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCgkOMTA2NjRQ0lEyBGIzICtWB0XYCFnYLTgk2NDY0NQUpNgRpMnIxBzIwZR0wifpjC4ZERJmaGRgYGgClPACYmMjoIWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Srv-computer" = _t, App = _t, #"Sum of DiskSizeInGB" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Srv-computer", type text}, {"App", type text}, {"Sum of DiskSizeInGB", Int64.Type}}),
    BuffList = List.Buffer(#"Changed Type"[#"Srv-computer"]),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "SizePerApp", each Number.Round([Sum of DiskSizeInGB]/List.Count(List.Select(BuffList, (x)=> x=[#"Srv-computer"])),1))
in
    #"Added Custom"

 

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Replace each _ = [#"Srv-computer"] with (x)=>x= [#"Srv-computer"]

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCgkOMTA2NjRQ0lEyBGIzICtWB0XYCFnYLTgk2NDY0NQUpNgRpMnIxBzIwZR0wifpjC4ZERJmaGRgYGgClPACYmMjoIWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Srv-computer" = _t, App = _t, #"Sum of DiskSizeInGB" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Srv-computer", type text}, {"App", type text}, {"Sum of DiskSizeInGB", Int64.Type}}),
    BuffList = List.Buffer(#"Changed Type"[#"Srv-computer"]),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "SizePerApp", each Number.Round([Sum of DiskSizeInGB]/List.Count(List.Select(BuffList, (x)=> x=[#"Srv-computer"])),1))
in
    #"Added Custom"

 

Great! Works like a charm 🙂

Thanks!

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