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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
EmaVasileva
Helper V
Helper V

Calculated column - From/To formula

Hi team,

I need a help with creating two calculated columns. Currently, I have the following data:

9.png

 

 

 

 

 


The result I'm looking for is:

8.png

 

 

 

 

 

 

 

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.

1 ACCEPTED 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:

4.JPG

 

Regards,

lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@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 :

new3.png
End result should be:

new2.png

Thank you.

mahoneypat
Employee
Employee

Please try these two column expressions to get your desired results

 

From = var thisrow = Metric[Metric]
var thisIDmin = CALCULATE(MIN(Metric[Metric]), ALLEXCEPT(Metric, Metric[ID]))
return IF(thisrow=thisIDmin, 0, thisIDmin)
 
To = Metric[Metric] + Metric[From]
 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI 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 :
new3.png
End result should be:
new2.png



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:

4.JPG

 

Regards,

lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lili6-msft 

Thank you so much. It works! 

Have a great day!

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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.