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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Creating a Measure To Count the Number of Times a Condition Occurred at some Future Date

Hello all,

 

I am looking for a measure that counts the number of times that a certain condition happens. The condition is such that a status changes from 0 (at some date) and then to 1 at a later date in a fact table.

 

Below is an example of the fact table:

 

Power BI Fact Table.PNG

 

Here is the desired output:

 

Power BI Example2.PNG

 

 

Here is the link to the .pbix file

 

I am assuming that COUNTX has to be used here but I am not sure how to formulate the expression so that the measures only searches the dates in which the condition has not already been met. Any tips are greatly appreciated! Thanks!

2 ACCEPTED SOLUTIONS
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

Please kindly let me know if you'd like to get below results:

Please filter the measure is not blank:

Count = var a = CALCULATE(MAX(Transactions[Date]),FILTER(ALL(Transactions),[Date]<MAX(Transactions[Date])&&[Status]="0"),VALUES(Transactions[Material]))
Return
COUNTX(Transactions,a)

09.PNG

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

View solution in original post

Anonymous
Not applicable

I was able to come up with the solution using EARLIER( ). Here is the DAX I used:

 

PowerBI Solution.PNG

 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

I was able to come up with the solution using EARLIER( ). Here is the DAX I used:

 

PowerBI Solution.PNG

 

v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

Please kindly let me know if you'd like to get below results:

Please filter the measure is not blank:

Count = var a = CALCULATE(MAX(Transactions[Date]),FILTER(ALL(Transactions),[Date]<MAX(Transactions[Date])&&[Status]="0"),VALUES(Transactions[Material]))
Return
COUNTX(Transactions,a)

09.PNG

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
smpa01
Super User
Super User

@Anonymous  can you please try this

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

Hi, that solution did not work, my apologies for providing the sample table that may have been unclear. I have included a screenshot of the measure with a different table. Please note that the correct output should show a count of 2 for A and 1 for C 

 

PBI Test.PNG

 

Now I am confused. What exactly you want. If you want sum 0, that B should also be. Last time it seems you want to sum when you one the value as 0

Sum of 0

 

sumx(table,if(table[status]=0,1,0))

Anonymous
Not applicable

To clarify the count is the number of incidences in which some material switches from being status of 0 to status of 1. So in the example above A goes from 0 to 1 a total of 2 times and C goes from 0 to 1 a total of 1 time., B never has a status of 0 then 1 (in the future), so that count is 0.

amitchandak
Super User
Super User

as column you can filter like
if(countx(table[status])-sumx(table[status])>1,1,0)

use this as filter



As measure to be displayed with material
calculate(countrows(table),values([material]),filter(table,(countx(table[status])-sumx(table[status]))>0))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.