Forum Discussion
first occurrence of a value.
- 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
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
- Robert19816 years ago
Helper III
My table has 282,000 records. I tried the formula for the first occurence.
But my machine can't finish the calculation
- Anonymous5 years agoNot applicable
How can I dynamically check the first occurence when i change the date values in a slicer
- Ashish_Mathur5 years ago
Super User
Hi,
Share some data, describe the question and show the expected result.
- Anonymous5 years agoNot applicable
Hi,
I need to create a dynamic column where the first occurance/flag column changes based on the slicer date range. Here's the sample data
So, if I select the data range from March,2019 to August,2019 the resulted column should have only 4 rows and their first occurance flaged 1.
- powerbifuddaa5 years ago
Helper II
Thank you for this. I have the same question. However "EARLIER" does not work when I try to use it. Have no idea what I do wrong...I read on the internet that "EARLIER" is not recommended... Is there an alternative way to answer the same question (showing the first occurence of a number in a table). Thank you!
first occurrence check = IF ( CALCULATE ( COUNTROWS ( Test1 ), FILTER ( ALLEXCEPT ( Test1, Test1[MRN] ), Test1[Index] <= EARLIER ( Test1[Index] ) ) ) > 1, 0, 1 )- spool974 years agoNew Member
I know this is almost a year late, but if you happen to still want to know this you should know EARLIER is mostly used in the context of calculated columns. You can find more informations about it here
https://blog.enterprisedna.co/how-to-use-the-earlier-function-in-power-bi-a-dax-tutorial/
- cgallegos4 years agoRegular Visitor
Hi Yuliana,
Would you be able to help turn this formula so that it counts the number of occurance? For example, I'd want the second occurence of HIR to say 2 or the third occurance of DTA to say 3 for each employee ID.
Occurence = IF(CALCULATE(COUNTROWS('Records'),FILTER(ALLEXCEPT('Records','Records'[Empl ID],'Records'[Action]),VALUE('Records'[Effective Date - Job Dta])<=VALUE(EARLIER('Records'[Effective Date - Job Dta]))))>1,0,1)Thank you in advance!!
- Anonymous2 years agoNot applicable
Hello, thank you so much for the answer.
What if there are ties in the date and we would like to randomly choose one of the ties to flag it as first occurrence?