Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi, i have a set of data as shown below.
How to calculate if the same date exist in the next line for same ID, then sum it, if not just take the hours in Col C.
Solved! Go to Solution.
If you are looking for a calculated column, you might try this code:
HoursCombiner =
VAR currentIndex = T[Index]
VAR currentID = T[ID]
VAR nextDate = MINX(FILTER(T, T[Index] > currentIndex && T[ID] = currentID), T[Date])
RETURN
IF(T[Date] = nextDate,
SUMX(FILTER(T, T[Date] <= nextDate && T[ID] = currentID && T[Index] >= currentIndex), T[Hours]),
T[Hours])
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.
Check out my latest demo report in the data story gallery.
Stand with Ukraine!
Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/
Thank you!
If you are looking for a calculated column, you might try this code:
HoursCombiner =
VAR currentIndex = T[Index]
VAR currentID = T[ID]
VAR nextDate = MINX(FILTER(T, T[Index] > currentIndex && T[ID] = currentID), T[Date])
RETURN
IF(T[Date] = nextDate,
SUMX(FILTER(T, T[Date] <= nextDate && T[ID] = currentID && T[Index] >= currentIndex), T[Hours]),
T[Hours])
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.
Check out my latest demo report in the data story gallery.
Stand with Ukraine!
Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/
Thank you!
@PBI_newuser , Try new column like
sumx(filter(Table, [ID] =earlier([ID]) && [Date] =earlier([Date]) ),[hours])
Hi @amitchandak , by using the column you have shared, the total hours for B-123 on 20/12/2019 is 35.0.
However, I would like to combine once only if the ID and date is the same, and add the second line (larger) value. For example, the HoursCombiner for B-123 on 20/12/2019 should be 8.0+9.5+9.5 = 27.0.
@PBI_newuser , You have to add an index column in the power query and try a new column - https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi
sumx(filter(Table, [ID] =earlier([ID]) && [Date] =earlier([Date]) && [Index] >earlier([index]) && [Hours] > earlier([hours]) ),[hours])
@PBI_newuser , Only need one small change to the formula