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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
edubcardoso
Advocate I
Advocate I

Subtract values from the previest row

Hey!

I need to subtract initial KMS from the final KMS in previous value,  , to check errors

dayuserinitial KMSfinal kmsDiffmeasure i wanna calculate
10-06-2022110012626 
10-06-2022225628630 
13-06-2022113018050130 - 126 = 4
14-06-20221180200200
15-06-2022120525045

205 - 200 = 5

I cant use index ranking from the power query because a have a lot of users.

Can you help me, please ?

Sorry for my bad english

Thanks!

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @edubcardoso ,

Here are the steps you can follow:

1. Create calculated column.

 

Rank_Column = RANKX(FILTER(ALL('Table'),'Table'[user]=EARLIER('Table'[user])),'Table'[day],,ASC)
Mod_column = MOD('Table'[Rank_Column],2)

 

vyangliumsft_0-1655780375751.png

2. Create measure.

 

Measure1 =
var _1=CALCULATE(SUM('Table'[initial KMS]),FILTER(ALL('Table'),'Table'[user]=MAX('Table'[user])&&'Table'[Mod_column]=MAX('Table'[Mod_column])&&'Table'[Rank_Column]=MAX('Table'[Rank_Column])))
return
IF(
    MAX('Table'[Mod_column])=1,0,_1
)
Measure2 =
CALCULATE(SUM('Table'[final kms]),FILTER(ALL('Table'),'Table'[user]=MAX('Table'[user])&&'Table'[Mod_column]=MAX('Table'[Mod_column])+1&&'Table'[Rank_Column]=MAX('Table'[Rank_Column])-1))
measure calculate =
[Measure1] - [Measure2]

 

3. Result:

vyangliumsft_1-1655780375753.png

 

Best Regards,

Liu Yang

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
v-yangliu-msft
Community Support
Community Support

Hi  @edubcardoso ,

Here are the steps you can follow:

1. Create calculated column.

 

Rank_Column = RANKX(FILTER(ALL('Table'),'Table'[user]=EARLIER('Table'[user])),'Table'[day],,ASC)
Mod_column = MOD('Table'[Rank_Column],2)

 

vyangliumsft_0-1655780375751.png

2. Create measure.

 

Measure1 =
var _1=CALCULATE(SUM('Table'[initial KMS]),FILTER(ALL('Table'),'Table'[user]=MAX('Table'[user])&&'Table'[Mod_column]=MAX('Table'[Mod_column])&&'Table'[Rank_Column]=MAX('Table'[Rank_Column])))
return
IF(
    MAX('Table'[Mod_column])=1,0,_1
)
Measure2 =
CALCULATE(SUM('Table'[final kms]),FILTER(ALL('Table'),'Table'[user]=MAX('Table'[user])&&'Table'[Mod_column]=MAX('Table'[Mod_column])+1&&'Table'[Rank_Column]=MAX('Table'[Rank_Column])-1))
measure calculate =
[Measure1] - [Measure2]

 

3. Result:

vyangliumsft_1-1655780375753.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

SpartaBI
Community Champion
Community Champion

@edubcardoso you need a measure or a calculated column?
The table you sent is a table visual or this is how your data looks like in the model table:

SpartaBI_0-1655309609299.png

 



@SpartaBI 
A measure.

Thanks for the help!

@edubcardoso my pleasure. 
Can you share a picture of how your data table look like.
Also, in the table you showed, which one is a column there and which one is a measure? And if you have measures there, what are they? How do you calculate currently initial KMS and final kms ?

The table the I have looks like the pic you showed, only missing 2 ou 3 column like the name of the user, but that columns are not needed in this measure.

The only measure in the table is the last column . Its the one i wanna calculate.

The KMs (final and initial) are filled in by the user in a software

The main goal of the measure its to see where the user made a mistake

@edubcardoso will pm you

@edubcardoso I sent you a private message

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors