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

Be 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

Reply
cksmth
Frequent Visitor

Replication of COUNTIF in DAX

Hi, 

 

I am trying to replicate the below formula in power BI to number the first event in a squence (or date the new status was changed)

 

C = Quote Number

E = New Status

G= Date

 

=COUNTIFS($C:$C,C2,$E:$E,E2,$G:$G,"<"&$G2)+COUNTIFS($C$2:$C2,C2,$E$2:$E2,E2,$G$2:$G2,G2)

 

Any help is appreciated 🙂

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @cksmth -  you can use the CALCULATE and FILTER functions to count rows based on the conditions specified.

you can replace with your model table name

create a measure as below:

 

EventNumber =
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
'Table'[Quote Number] = EARLIER('Table'[Quote Number]) &&
'Table'[New Status] = EARLIER('Table'[New Status]) &&
'Table'[Date] < EARLIER('Table'[Date])
)
) +
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
'Table'[Quote Number] = EARLIER('Table'[Quote Number]) &&
'Table'[New Status] = EARLIER('Table'[New Status]) &&
'Table'[Date] = EARLIER('Table'[Date])
)
)

Hope this helps.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

3 REPLIES 3
Kedar_Pande
Community Champion
Community Champion

@cksmth 

Create a new column:

Event_Number =
VAR CurrentQuote = 'YourTable'[Quote Number]
VAR CurrentStatus = 'YourTable'[New Status]
VAR CurrentDate = 'YourTable'[Date]

RETURN
CALCULATE(
COUNTROWS('YourTable'),
'YourTable'[Quote Number] = CurrentQuote,
'YourTable'[New Status] = CurrentStatus,
'YourTable'[Date] < CurrentDate
)
+
CALCULATE(
COUNTROWS('YourTable'),
'YourTable'[Quote Number] = CurrentQuote,
'YourTable'[New Status] = CurrentStatus,
'YourTable'[Date] = CurrentDate,
'YourTable'[Date] <= EARLIER('YourTable'[Date])
)

💌If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

Bibiano_Geraldo
Resident Rockstar
Resident Rockstar

Hi,

 

Create a new column and paste the following Dax.
Make sure to replace columns and table names with your owns.

if you are satisfied with this answer, please, mark it as solution.

CalculatedColumn =
VAR CurrentQuote = 'YourTable'[Quote Number]
VAR CurrentStatus = 'YourTable'[New Status]
VAR CurrentDate = 'YourTable'[Date]

RETURN
CALCULATE(
COUNTROWS('YourTable'),
FILTER(
'YourTable',
'YourTable'[Quote Number] = CurrentQuote &&
'YourTable'[New Status] = CurrentStatus &&
(
'YourTable'[Date] < CurrentDate ||
(
'YourTable'[Date] = CurrentDate &&
EARLIER('YourTable'[Quote Number]) = CurrentQuote &&
EARLIER('YourTable'[New Status]) = CurrentStatus
)
)
)
)

I hope this helps! 
If you found this answer helpful:
✔️ Mark it as the solution to help others find it faster.
 Give it a like to show your appreciation!

Thank you for contributing to our amazing Power BI community! 
rajendraongole1
Super User
Super User

Hi @cksmth -  you can use the CALCULATE and FILTER functions to count rows based on the conditions specified.

you can replace with your model table name

create a measure as below:

 

EventNumber =
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
'Table'[Quote Number] = EARLIER('Table'[Quote Number]) &&
'Table'[New Status] = EARLIER('Table'[New Status]) &&
'Table'[Date] < EARLIER('Table'[Date])
)
) +
CALCULATE(
COUNTROWS('Table'),
FILTER(
'Table',
'Table'[Quote Number] = EARLIER('Table'[Quote Number]) &&
'Table'[New Status] = EARLIER('Table'[New Status]) &&
'Table'[Date] = EARLIER('Table'[Date])
)
)

Hope this helps.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.