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

Calculate row differences under different category

ronlolololo_0-1594856513105.png

Hi Team, I am looking for solution for this issue. 

I would want to calculate the difference between each day under each county. Wondering how to achieve this. Please advised. Thanks. 

 

1 ACCEPTED SOLUTION
ronlolololo
Helper I
Helper I
8 REPLIES 8
ronlolololo
Helper I
Helper I

Hi @ronlolololo 

I'm so glad you have solved your porblem. And thanks for sharing this method for us to solve this issue. 

Please mark your reply as a solution.

Best Regards,

Rico Zhou

 

Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

=Table[DateKey]-calculate(max([datekey]),filter(table,table[County Name]=earlier(table[County Name])&&table[DateKey]<earlier(table[DateKey])))

Ensure that your Datekey column is formatted as a Date field.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur 

 

Thanks for the response!

I typed in the code and it tured out this way. Let me know if I did anything wrong. Thanks.

PowerBI2.JPG

It looks fine to me.  Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

 
lbendlin
Super User
Super User

I see you have an index column - that's good.

 

1. for each line in your visual (the filter context) get the county name

 

var cn = SELECTEDVALUE(table[County Name])

 

2. get the current index

 

var id = SELECTEDVALUE(table[Index])

 

3. get the maximum index for the same county that is smaller than your current index

 

var prev_id=CALCULATE(MAX(table[Index]),ALLSELECTED(table),table[County Name]=cn,table[Index]<id)

 

4. lastly, get the value for that index.

 

var val = CALCULATE((whatever),ALLSELECTED(table),table[Index]=prev_id)

 

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.