Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hello all,
I have a date column, a category column and a value column. I want to be able to sum the value column with the previous column only, and if the sum is 2 (the value can be 1 or 0 for the column) for the given category, then it should log the earlier date of the two. I am having trouble figuring out the logic. Would appreciate the support.
Solved! Go to Solution.
Hi @ps92 ,
I suggest you to add an [Index] column in your table. Then create a measure.
Measure =
VAR _STEP1 =
ADDCOLUMNS (
ALL ( 'Table' ),
"Last0Date",
IF (
'Table'[Below Target] = 0,
BLANK (),
CALCULATE (
MIN ( 'Table'[Date] ),
FILTER (
ALLEXCEPT ( 'Table', 'Table'[Section] ),
'Table'[Date] > EARLIER ( 'Table'[Date] )
&& 'Table'[Below Target] = 0
)
)
)
)
VAR _STEP2 =
ADDCOLUMNS (
_STEP1,
"Running Total",
SUMX (
FILTER (
_STEP1,
[Date] <= EARLIER ( [Date] )
&& [Section] = EARLIER ( [Section] )
&& [Last0Date] = EARLIER ( [Last0Date] )
),
[Below Target]
)
)
RETURN
MAXX ( FILTER ( _STEP2, [Index] = MAX ( 'Table'[Index] ) ), [Running Total] )
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @parry2k , thank you for the response. To elaborate more, I have a date column, a line number(a categorical column) and the binary output based on a certain condition. I want to raise a flag if the output is 1 for two consecutive days. And I also want to log the latest date of the consecutive days. If it is 7 consecutive days, I want to raise a different flag, and log the date again. But the flags should be for the categorical column. I want to be able to see when the flags were raised. The meain reason is to monitor the date of consecutive occurences and consecutive 5 occurences. The measure column can be used to find the date and consecutive days. Happy to provide more details if needed. Thanks!!
Date | Section | Below Target | Measure |
01-Nov-23 | Line 1 | 1 | 1 |
02-Nov-23 | Line 1 | 0 | 0 |
03-Nov-23 | Line 1 | 0 | 0 |
06-Nov-23 | Line 1 | 1 | 1 |
07-Nov-23 | Line 1 | 1 | 2 |
08-Nov-23 | Line 1 | 0 | 0 |
09-Nov-23 | Line 1 | 1 | 1 |
10-Nov-23 | Line 1 | 0 | 0 |
01-Nov-23 | Line 2 | 1 | 1 |
02-Nov-23 | Line 2 | 0 | 0 |
03-Nov-23 | Line 2 | 0 | 0 |
06-Nov-23 | Line 2 | 1 | 1 |
07-Nov-23 | Line 2 | 1 | 2 |
08-Nov-23 | Line 2 | 1 | 3 |
09-Nov-23 | Line 2 | 1 | 4 |
10-Nov-23 | Line 2 | 0 | 0 |
Hi @ps92 ,
I suggest you to add an [Index] column in your table. Then create a measure.
Measure =
VAR _STEP1 =
ADDCOLUMNS (
ALL ( 'Table' ),
"Last0Date",
IF (
'Table'[Below Target] = 0,
BLANK (),
CALCULATE (
MIN ( 'Table'[Date] ),
FILTER (
ALLEXCEPT ( 'Table', 'Table'[Section] ),
'Table'[Date] > EARLIER ( 'Table'[Date] )
&& 'Table'[Below Target] = 0
)
)
)
)
VAR _STEP2 =
ADDCOLUMNS (
_STEP1,
"Running Total",
SUMX (
FILTER (
_STEP1,
[Date] <= EARLIER ( [Date] )
&& [Section] = EARLIER ( [Section] )
&& [Last0Date] = EARLIER ( [Last0Date] )
),
[Below Target]
)
)
RETURN
MAXX ( FILTER ( _STEP2, [Index] = MAX ( 'Table'[Index] ) ), [Running Total] )
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello Rico,
This actually worked to solve the problem I was facing.
Is there a way to be able to display the date of 2 occurences, and only show the date of the next 2 occurences after a certain time frame?
For example, a measure that gives me the date of first 2 occurences,i.e 7-11-2023, but if there is 2 occurences in the next 2 weeks, the measure wont give me that date, it will only gicve me the next 2 consecutive occurences that take place after 2 weeks.
I'll try to solve it myself as well. But thank you for the above solution. 🙂
@ps92 can you provide the sample data and the expected output? Read this post to get your answer quickly.
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.