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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
ps92
Frequent Visitor

Need help with logging date and information

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.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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.

vrzhoumsft_0-1701054502303.png

 

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.

 

View solution in original post

4 REPLIES 4
ps92
Frequent Visitor

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!!

DateSectionBelow TargetMeasure
01-Nov-23Line 111
02-Nov-23Line 100
03-Nov-23Line 100
06-Nov-23Line 111
07-Nov-23Line 112
08-Nov-23Line 100
09-Nov-23Line 111
10-Nov-23Line 100
01-Nov-23Line 211
02-Nov-23Line 200
03-Nov-23Line 200
06-Nov-23Line 211
07-Nov-23Line 212
08-Nov-23Line 213
09-Nov-23Line 214
10-Nov-23Line 200
Anonymous
Not applicable

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.

vrzhoumsft_0-1701054502303.png

 

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?

ps92_0-1701093283788.png

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. 🙂

parry2k
Super User
Super User

@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.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors