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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Buckeyes2016
New Member

Calculated Column: Return a value only once on the same day for the same resource.

Hello,

 

I am working to create a column in my PowerBI TimeEntry data table that returns the value 8 for "available hours" only once for a given employee on a given date. My data currently looks like the first three columns on the table below and I would like to create a 4th column that looks like the table below. I have tried several approaches and have not found something that works. Thank you so much for your help!

 

ResourceDateAvailable HoursReturn
Employee 11/1/202388
Employee 11/1/20238 
Employee 11/1/20238 
Employee 12/1/202388
Employee 13/1/202388
Employee 13/1/20238 
Employee 22/1/202288
Employee 22/1/20228 
Employee 22/1/20228 
Employee 24/1/202288
Employee 25/1/202288
Employee 25/1/20228 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Buckeyes2016 ,

You can follow the steps below to get it, please find the details in the attachment.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs0tyMmvTE1VMFTSUTLUN9Q3MjAyBjItlGJ1qCprhFfWmCxZI7wmUy5rglfWlGjZWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Resource = _t, Date = _t, #"Available Hours" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Resource", type text}, {"Date", type date}, {"Available Hours", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Resource", Order.Ascending}, {"Date", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Resource","Date","Available Hours"}, {{"Index", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Index" = Table.ExpandTableColumn(#"Grouped Rows", "Index", {"Index"}, {"Index"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Index", "Return", each if [Index]=1 then [Available Hours] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

vyiruanmsft_0-1690945321173.png

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Buckeyes2016 ,

You can follow the steps below to get it, please find the details in the attachment.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs0tyMmvTE1VMFTSUTLUN9Q3MjAyBjItlGJ1qCprhFfWmCxZI7wmUy5rglfWlGjZWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Resource = _t, Date = _t, #"Available Hours" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Resource", type text}, {"Date", type date}, {"Available Hours", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Resource", Order.Ascending}, {"Date", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Resource","Date","Available Hours"}, {{"Index", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Index" = Table.ExpandTableColumn(#"Grouped Rows", "Index", {"Index"}, {"Index"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Index", "Return", each if [Index]=1 then [Available Hours] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

vyiruanmsft_0-1690945321173.png

Best Regards

Buckeyes2016
New Member

Buckeyes2016_0-1690849886306.png

Here is a better view of what I am trying to return. Thanks!

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.

Top Solution Authors