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
Anonymous
Not applicable

Dynamic if sum of cells in subsequent order by date is greater than...

Sorry for poor title, it was difficult to describe.

 

Here is some example data:

Date

Type

Hours

Long-term

04.05.2020

Work

8

0

05.05.2020

Absence

8

0

06.05.2020

Absence

8

0

07.05.2020

Work

8

0

08.05.2020

Absence

8

1

11.05.2020

Absence

8

1

12.05.2020

Absence

8

1

13.05.2020

Absence

8

1

14.05.2020

Work

8

0

 

I need to create a measure that says, 

Long-term = 

if Type "Absence" && Sum(Hours) > 40, 1, 0

 

But, they have to be in a subsequential date-order like in the  example above. 

 

If there is a type Work in between, the measure returns false

 

Date

Type

Hours

Long-term

04.05.2020

Work

8

0

05.05.2020

Absence

8

0

06.05.2020

Absence

8

0

07.05.2020

Work

8

0

08.05.2020

Absence

8

0

11.05.2020

Absence

8

0

12.05.2020

Work

8

0

13.05.2020

Absence

8

0

14.05.2020

Work

8

0

 

Is this possible? Here's a link to a .pbix file if you want to try and solve this. 

 

6 REPLIES 6
Anonymous
Not applicable

HI @Anonymous,

You can use the following calculated column formula to check the continuous range between two work date:

Column =
VAR _prev =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( 'Table', [Date] < EARLIER ( 'Table'[Date] ) && [Type] = "Work" )
    )
VAR _next =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        FILTER ( 'Table', [Date] > EARLIER ( 'Table'[Date] ) && [Type] = "Work" )
    )
VAR continues =
    IF (
        _prev <> BLANK ()
            && _next <> BLANK (),
        CALCULATE (
            SUM ( 'Table'[Hours] ),
            FILTER (
                ALL ( 'Table' ),
                [Type] <> "Work"
                    && [Date] IN CALENDAR ( _prev, _next )
            )
        )
    )
RETURN
    IF ( [Type] = "Absence" && continues > 40, 1, 0 )

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

v-shex-msft, I am having issues for each of the EARLIER ( 'Table'[Date] )


Anonymous
Not applicable

HI @Anonymous,

What issue did you face? Please share more detailed information or some dummy data to help us clarify your scenario.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

The .pbix file is found in the first post.

Using your measure, it was unable to refer to the data columns and the last Type:

measureissue.PNG

Anonymous
Not applicable

HI @Anonymous,

My formula is calculated column, it not able to use in measure expression. If you want a measure version, you can try to use the below formula:

measure=
VAR currDate =
    MAX ( 'Table'[Date] )
VAR currType =
    SELECTEDVALUE ( 'Table'[Type] )
VAR _prev =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Date] < currDate && [Type] = "Work" )
    )
VAR _next =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Date] > currDate && [Type] = "Work" )
    )
VAR continues =
    IF (
        _prev <> BLANK ()
            && _next <> BLANK (),
        CALCULATE (
            SUM ( 'Table'[Hours] ),
            FILTER (
                ALL ( 'Table' ),
                [Type] <> "Work"
                    && [Date] IN CALENDAR ( _prev, _next )
            )
        )
    )
RETURN
    IF ( currType = "Absence" && continues > 40, 1, 0 )

Regards,
Xiaoxin Sheng

Greg_Deckler
Community Champion
Community Champion

Right, so I am not 100% on your requirement, but I do know that you will need something like Cthulhu at some point in trying to solve it. https://community.powerbi.com/t5/Quick-Measures-Gallery/Cthulhu/m-p/509739#M211



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors