Forum Discussion

rabiafarooq's avatar
rabiafarooq
Icon for Helper I rankHelper I
8 years ago
Solved

first occurrence of a value.

I have a table called Pharmacy_Issuance, in which i have to calculate the number of prescriptions for new or refills for certain medicines. So what i want to do is if the medical record number[MRN] o...
  • v-yulgu-msft's avatar
    8 years ago

    Hi rabiafarooq,

     

    Add an index column first. Then, create a new column like below:

    first occurrence check =
    IF (
        CALCULATE (
            COUNTROWS ( Test1 ),
            FILTER (
                ALLEXCEPT ( Test1, Test1[MRN] ),
                Test1[Index] <= EARLIER ( Test1[Index] )
            )
        )
            > 1,
        0,
        1
    )

     

    However, if there is a date column in your dataset, there is no need to add index column, you can directly refer to date field in above formula.

     

    Best regards,

    Yuliana Gu