March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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] occurs for the first time in column its for new medicine else its a refill. i want to add two calculated column, if new then 1 else 0 and same for refills. please guide.
Solved! Go to Solution.
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, I need help, I am looking for a measure than can return the count of customers buying buying a particular product say product A for the first time. It can be a new customer or an exsiting customer.
I have a data runing from Jan 2022 to Jan 2023. I need to get the number of customers buying product spirits for the first time ever in the month of Jan 2023.
Any help will be appreciated.
Hi,
Ensure that you have a Calendar Table with calculated column formulas for Year, Month name and Month number. Sort the Month name column by the Month number. Create a relationship (Many to One and Single) from the Date column of the Data Table to the Date column of the Calendar Table. Write these measures:
First date = calculate(min(Data[Date]),datesbetween(calendar[date],minx(all(calendar),calendar[date]),max(calendar[date])))
First customers = countrows(filter(values(Data[Customer]),[First date]>=min(calendar[date])))
To your visual, drag Year and Month from the Calendar Table. In the slicer, select spirits.
Hope this helps.
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
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?
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.
Thank you in advance!!
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 )
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/
How can I dynamically check the first occurence when i change the date values in a slicer
Hi,
Share some data, describe the question and show the expected result.
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.
Hi,
Assuming the slicer is from the Calendar Table and the Dates in the Table visual are from the Data Table, try this measure
=if(startofmonth(Data[Date])=min(calendar[date]),1,0)
Thankyou, this measure works. But, is there a way that i can optimise by using the slicer from the Data Table?.
Because if I use the calender table, the resulted table is having six rows and I want the rows from the selected range only
Hi,
Create a relationship from the Date column of the Data Table to the Date column of the Calendar Table. You must create a Calendar Table.
My table has 282,000 records. I tried the formula for the first occurence.
But my machine can't finish the calculation
please, anyone?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
134 | |
91 | |
90 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
72 | |
68 |