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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

MULTIPLE calculate(sum()) columns over same area (Circular dependency issue)

Hello everyone,

 

I have a timesheet report that displays as follows, where each row represents an entry (each job logged).  There are columns (Mon-Sun) with the entered hours, and then columns for comments for each day which represent the "type" of job code (A, W, D, I, R, F).

 

I am looking for a way to total the hours for each "type", relative to the row it is in.  I tried making a column: "Type A = calculate(sum('Timesheet'[Mon]),'Timesheet'[Mon - Comment]="A") + calculate(sum('Timesheet'[Tue]),'Timesheet'[Tue- Comment]="A") + etc....... which accomplished what I wanted for type A.  But as soon as I tried to make the next column for the next type: "Type W = calculate(sum('Timesheet'[Mon]),'Timesheet'[Mon - Comment]="W")etc....., I was given a "circular dependency" error.

 

MonTueWedThuFriSatSunTotalMon - CommentTue - CommentWed - CommentThu - CommentFri - CommentSat - CommentSun - Comment
888--------24IDR--------
13----------4AA----------
--3----------3--R----------
72----------9RI----------

 

In excel, I was able to accomplish this with the following formula, but am looking for the equivalent solution in Power BI. 

Gorlinjer_0-1648663638591.png

 

Thank you!

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s3PU9JRCilNBZLhqSkgdkYpkHQrygSSwYklILIUrCa/JDEHSAN1KOgqOOfn5qbmlUD0ovCBpqDKZ5Si8IEmo/CBdqDyS5HNj9WJVrIAisKwri4mYWQCJDyB2AWIg7AqAhljCGQa4zACTICMcYRiHIpA5oDZeA2CS2J3DNwkc5Dj8RlkCTXDE485sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t, #"(blank).5" = _t, #"(blank).6" = _t, #"(blank).7" = _t, #"(blank).8" = _t, #"(blank).9" = _t, #"(blank).10" = _t, #"(blank).11" = _t, #"(blank).12" = _t, #"(blank).13" = _t, #"(blank).14" = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Replaced Value" = Table.ReplaceValue(#"Promoted Headers","--",null,Replacer.ReplaceValue,{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Total", "Mon - Comment", "Tue - Comment", "Wed - Comment", "Thu - Comment", "Fri - Comment", "Sat - Comment", "Sun - Comment"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"Mon", Int64.Type}, {"Tue", Int64.Type}, {"Wed", Int64.Type}, {"Thu", Int64.Type}, {"Fri", Int64.Type}, {"Sat", Int64.Type}, {"Sun", Int64.Type}, {"Total", Int64.Type}, {"Mon - Comment", type text}, {"Tue - Comment", type text}, {"Wed - Comment", type text}, {"Thu - Comment", type text}, {"Fri - Comment", type text}, {"Sat - Comment", type text}, {"Sun - Comment", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "A", each (if [#"Mon - Comment"]="A" then [Mon] else 0) + 
(if [#"Tue - Comment"]="A" then [Tue] else 0) + 
(if [#"Wed - Comment"]="A" then [Wed] else 0) + 
(if [#"Thu - Comment"]="A" then [Thu] else 0) + 
(if [#"Fri - Comment"]="A" then [Fri] else 0) + 
(if [#"Sat - Comment"]="A" then [Sat] else 0) + 
(if [#"Sun - Comment"]="A" then [Sun] else 0))
in
    #"Added Custom"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

 

Note: I only added the "A" column.  You can how it is done, and can add the other ones yourself .

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s3PU9JRCilNBZLhqSkgdkYpkHQrygSSwYklILIUrCa/JDEHSAN1KOgqOOfn5qbmlUD0ovCBpqDKZ5Si8IEmo/CBdqDyS5HNj9WJVrIAisKwri4mYWQCJDyB2AWIg7AqAhljCGQa4zACTICMcYRiHIpA5oDZeA2CS2J3DNwkc5Dj8RlkCTXDE485sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t, #"(blank).5" = _t, #"(blank).6" = _t, #"(blank).7" = _t, #"(blank).8" = _t, #"(blank).9" = _t, #"(blank).10" = _t, #"(blank).11" = _t, #"(blank).12" = _t, #"(blank).13" = _t, #"(blank).14" = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Replaced Value" = Table.ReplaceValue(#"Promoted Headers","--",null,Replacer.ReplaceValue,{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Total", "Mon - Comment", "Tue - Comment", "Wed - Comment", "Thu - Comment", "Fri - Comment", "Sat - Comment", "Sun - Comment"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"Mon", Int64.Type}, {"Tue", Int64.Type}, {"Wed", Int64.Type}, {"Thu", Int64.Type}, {"Fri", Int64.Type}, {"Sat", Int64.Type}, {"Sun", Int64.Type}, {"Total", Int64.Type}, {"Mon - Comment", type text}, {"Tue - Comment", type text}, {"Wed - Comment", type text}, {"Thu - Comment", type text}, {"Fri - Comment", type text}, {"Sat - Comment", type text}, {"Sun - Comment", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "A", each (if [#"Mon - Comment"]="A" then [Mon] else 0) + 
(if [#"Tue - Comment"]="A" then [Tue] else 0) + 
(if [#"Wed - Comment"]="A" then [Wed] else 0) + 
(if [#"Thu - Comment"]="A" then [Thu] else 0) + 
(if [#"Fri - Comment"]="A" then [Fri] else 0) + 
(if [#"Sat - Comment"]="A" then [Sat] else 0) + 
(if [#"Sun - Comment"]="A" then [Sun] else 0))
in
    #"Added Custom"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

 

Note: I only added the "A" column.  You can how it is done, and can add the other ones yourself .

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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