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
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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.