Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and a 50 percent discount on exams.
Get startedEarn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi team,
I need a help with creating two calculated columns. Currently, I have the following data:
The result I'm looking for is:
I need a formula to create the "From" and "To" columns.
First table row: The "From" column should looking for rows with the same ID on the same day ( for ex. May 4 - AT150) and to look for the lowest metric, when it founds it, it should return 0 on that row. The "To" column should return the same number as the one in Metric.
Second table row: The "From"column should took the same number as the previous one in "To" (first row). The "To" column should return the sum of "Metric" value + From value from the second row.
When the ID is changed the calculation should start from the beginning and the From column should contain 0.
Thank you in advance.
Solved! Go to Solution.
hi @EmaVasileva
If so, try this formula:
From =
CALCULATE(SUM('Table'[Metric]),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Date]<EARLIER('Table'[Date])))+0
To = 'Table'[From]+'Table'[Metric]
Result:
Regards,
lin
@EmaVasileva , new columns
from = maxx(filter(Table, [Metric] < earlier([Metric]) && [ID] = earlier([ID])),[Metric])+0
to = [from]+[Metric]
Hi @amitchandak
Thank you for the response. Any idea how the formula would like if we don't look to the date, just to ID. When the ID is uniqe and we have the same ID for five following days (May 4, May 5, May 6) the values from-to will calculate on basis of the previous row.
I have :
End result should be:
Thank you.
Please try these two column expressions to get your desired results
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hi @mahoneypat,
Thank you for the response. Any idea how the formula would like if we don't look to the date, just to ID. When the ID is uniqe and we have the same ID for five following days (May 4, May 5, May 6) the values from-to will calculate on basis of the previous row.
I have :
End result should be:
Thank you.
hi @EmaVasileva
If so, try this formula:
From =
CALCULATE(SUM('Table'[Metric]),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Date]<EARLIER('Table'[Date])))+0
To = 'Table'[From]+'Table'[Metric]
Result:
Regards,
lin
The expression I provided with the ALLEXCEPT is removing all the filters except the one on ID, so the date one is being removed now. If you want to only look on a certain date and ID, you could add a second column into the ALLEXCEPT().
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.