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
RappJ
Helper I
Helper I

Custom Colum using an if statement to compare dates in a grouped table and sum values

Good day all,

for each row in the main table I need to sum the hours colum in the nested group under the Runs and tools column. Any help is appreciated.


I belive I need an if statement in a custom column.

custom column = if(table.starttime >= Min Created on && table.startime <= Max Created On, sum(hours)

 

I know this code is not anywhere near correct i am just trying to explain what i am after.

RappJ_0-1646410994417.png

 

1 ACCEPTED SOLUTION
RappJ
Helper I
Helper I

Found a solution. I reckon I was not asking my question correctly.

Refer to Previous Row for Subgroups in Power Query

https://www.youtube.com/watch?v=IGF2-qfzDQs 

View solution in original post

6 REPLIES 6
RappJ
Helper I
Helper I

Found a solution. I reckon I was not asking my question correctly.

Refer to Previous Row for Subgroups in Power Query

https://www.youtube.com/watch?v=IGF2-qfzDQs 

watkinnc
Super User
Super User

Oh wait, what am I thinking?! Try this:

 

= Table.TransformColumn(PriorStepOrTableName, "RunsAndTools"  each Table.SelectRows(_, each [StartTime] >= [Min Created On] and [StartTime] <=[Max Created Time]))

 

Now you can click the Expand icon, choose "Aggregate", then Sum for the hours column. That should work. If not, then I really need to stop doing these with thoughts alone!

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Nate,
Thanks again, however I am unable to make this work either. I have included a screen cap of the advanced editor. I appreciate your assitance. ANy idea what I have done wrong?

 


#"Added Custom" = Table.TransformRows(#"Reordered Columns", "RunsAndTools" each Table.SelectRows(_, each [StartTime] >= [Min Created On] and [StartTime] <=[Max Created On]),

RappJ_0-1646666826253.png

 

Regards,
Jason

 

watkinnc
Super User
Super User

Try this:

 

= Table.AddColumn(PriorStepOrTableName, "TotalHours", each if [RunsAndTools][StartTime] >= [Min Created On] and [RunsAndTools][StartTime] <=[Max Created Time] then List.Sum([RunsAndTools][Hours]) else null)

 

See if that gives you what you need.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Nate,
Thank you for the reply. I am wondering if this error is due to user error, or did I impliment the code correctly and Power Query just does not like it. 

Expression.Error: We cannot apply operator >= to types List and Date.
Details:
Operator=>=
Left=[List]
Right=3/14/2018

It's my code. Let me go fire up the PC, this might not be one to do in my head...

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

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