Forum Discussion

Hussein_charif's avatar
1 year ago
Solved

Versus previous

Hi, i wanted to check if there is a similar function to the previous() visual calculation function but with measures?

Also, i have this visual calc:
Diff
IF(
ISINSCOPE([itemno]) &&
NOT ISINSCOPE([year]) &&
NOT ISINSCOPE([monthname]) &&
NOT ISINSCOPE([day]),
BLANK(),
IF(
ISBLANK(PREVIOUS([Total AVG Cost])),
0,
IF(
ISBLANK([Total AVG Cost]),
0,
[Total AVG Cost] - PREVIOUS([Total AVG Cost])
)
)
)

In the photo, you can see i have multiple itemNo. For the first row, for example itemNo 10002, the difference there is doing total avg cost of year 2022 of itemNo 10002 - total avg cost of year 2024 of itemNo 1, which is wrong. What can i do in this case to prevent the previous function from taking the total avg cost of different years?

  • lbendlin's avatar
    lbendlin
    1 year ago

    Yes, by using PREVIOUS() and indicating which direction you want to look.

5 Replies

  • There are no row numbers in DAX - you need to provide your own by specifying how you want the data sorted. Once you have that you can use the Window functions like OFFSET.

    • Hussein_charif's avatar
      Hussein_charif
      Helper V

      okay well, is there a way to solve the problem within visual calculations?

      • lbendlin's avatar
        lbendlin
        Super User

        Yes, by using PREVIOUS() and indicating which direction you want to look.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Hussein_charif ,

     

    Please provide sample data as well as your expected results.

     

    Best regards,
    Community Support Team_ Scott Chang