cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
bob57
Helper IV
Helper IV

Calculated column.

Hello,

Here is the original table:

bob57_1-1667082968029.png

I need a calculated column that will for each category display the difference in rating from the base rating for that category.

Here are what the column results would be:

bob57_2-1667083152190.png

Thank you,

Bob

1 ACCEPTED SOLUTION
eliasayy
Impactful Individual
Impactful Individual

hello @bob57 ,
pelase try :

Result = 
var _Currentcategory=Table1[Category Id]
var _Previousrating= MINX(FILTER(Table1,Table1[Rating]<EARLIER(Table1[Rating]) && Table1[Category Id]=_Currentcategory),Table1[Rating])
var _result=Table1[Rating]-_Previousrating
return IF(ISBLANK(_Previousrating),0,_result)

 

Screenshot 2022-10-30 010315.png

 

if you find this helpful, please consider accepting it as a solution and a kudos is appreciated

View solution in original post

6 REPLIES 6
bob57
Helper IV
Helper IV

I jumped the gun. There is still one small issue. The calculation must be relative to the Base. So with Category Id 3, record Id = 8 should be 0 (Base = TRUE) and record Id = 9 should be -1.4 (47.6 - 49). So sorry for not being more thorough at first glance.

bob57_0-1667086648861.png

 

eliasayy
Impactful Individual
Impactful Individual

is this the desired result?

Result = 
var _Currentcategory=Table1[Category Id]
var _Previousrating= MINX(FILTER(Table1,Table1[Rating]<EARLIER(Table1[Rating]) && Table1[Category Id]=_Currentcategory && Table1[Base] = "true"),Table1[Rating])
var _Previousrating2= MINX(FILTER(Table1,Table1[Rating]>EARLIER(Table1[Rating]) && Table1[Category Id]=_Currentcategory && Table1[Base] = "true"),Table1[Rating])
var _result=Table1[Rating]-_Previousrating -_Previousrating2
return IF(Table1[Base]="true",0,_result)

 

Screenshot 2022-10-30 020156.png

Yes. That does it. Thanks you!

bob57
Helper IV
Helper IV

This solution works beautifully! Now I have to figure out how it works. Thank you so much!

eliasayy
Impactful Individual
Impactful Individual

basically, in the MINX,in table selection , you want to filter the table first to show it - 1 row
hence using the earlier , since we used eralier([rating]) this will show 1 row before, the earlier can be used with ealier([rating],2) to show 2 rows before... 
hence we filtered the table to show the earlier result and substract current wit hearlier ,then we want to go from down to up so we use MINX to pick up the last one instead of going from up to down, in that case you will use MAXX like the example below:

Screenshot 2022-10-30 012613.png

eliasayy
Impactful Individual
Impactful Individual

hello @bob57 ,
pelase try :

Result = 
var _Currentcategory=Table1[Category Id]
var _Previousrating= MINX(FILTER(Table1,Table1[Rating]<EARLIER(Table1[Rating]) && Table1[Category Id]=_Currentcategory),Table1[Rating])
var _result=Table1[Rating]-_Previousrating
return IF(ISBLANK(_Previousrating),0,_result)

 

Screenshot 2022-10-30 010315.png

 

if you find this helpful, please consider accepting it as a solution and a kudos is appreciated

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors