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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
RichardT_78
Helper I
Helper I

adding row values

How do you calculate the last 3 row values into a messure?

 

E,g 

 

value  New Messure 

10             31

11             30

10             22

9               16

3                7 

4                4

 

 

4 REPLIES 4
HotChilli
Super User
Super User

Test it separately.

The FILTER statement creates a table so Hit New Table in powerbi and paste in that part of the statement.  You can use a variable instead of SELECTEDVALUE ( 'Events'[End Date/Time]) - hardcode the value to be a datetime you have in the table.

You can then see what that part of the code does.

 

Thank you, 

Yes i can see that beacuse the date and time stamp are identical they are both assinged the same value so i need to order the data. this is a problem to other data in the set. 

 

My code works for this small example but only because of the unique index

RichardT_78_1-1670496353369.png

 

 

I used this code to order the data that was filtered

index_move = RANKX(ALLSELECTED(CIN_Table),CALCULATE(SUM(CIN_Table[End Date/Time])),,ASC,Dense)
 
But it then looks like this:
 
RichardT_78_0-1670496182358.png

So i would need to either differenate the 1,1,2,2 to 1,2,3,4 or another option to count in groups of 4 ?

 

RichardT_78
Helper I
Helper I

I can use the date 

Cap1.PNG

I used the following code i found online which looks to SUM the filtered values, which would be around 24,366 but i dont understand the last part of the code which references the date and + 3 

 

if i look at the last 4 values the sum will always be the same unless data is missing due to it being repetitive

 

CIN Total =
CALCULATE (
    SUM ( 'Events'[EventId] ),
    FILTER (
        ALL ( 'Events' ),
        'Events'[EventId]
            && 'Events'[End Date/Time] >= SELECTEDVALUE ( 'Events'[End Date/Time])
            && 'Events'[End Date/Time]
                <= SELECTEDVALUE ( 'Events'[End Date/Time] ) + 3
    )
)
 
Any Help would be much appricated 
HotChilli
Super User
Super User

You filter the data to find the last 3 values based on some ordering (either an index or a date field) and then sum the values.
If the ordering is regular, it can be simpler e.g. index of 1,2,3,4 but otherwise you might have to use TOPN

Do you have an ordering?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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