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
jelledaems
Frequent Visitor

Measure for consecutive days between two dates

Hi everybody,

 

My best wishes for the New Year!

 

I have a table that contains which people get what kind of support from the government:

Person_NameType_SupportFrom_DateTo_Date
Joe W.money2021-06-012022-02-01
Jeffmoney2021-06-012021-11-29
Chrishouse2019-01-012022-12-31
Joe W.money2021-06-012021-08-01
Joe W.house2020-01-012022-12-31

 

Now I would like a way to get a list of all the Person_Name that have had Type_Support money from 2021-07-01 until at least 2021-12-31 without missing one day of support in that period. In the example Jeff would not come out of that list because he has only support until november. Joe W. will come out of that list (attention: he even has two support of money in that period at the same time)

 

I am a creator of reports, but I cannot change the dataset. This means that I would like to do this using a measure, so not using Power Query and preferably not adding calculated columns.

 

I have tried some things, but I'm not so good in DAX, so I got stuck. Is there anybody that cna put me on my way how to solve this?

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@jelledaems  you can create a measure like this

Measure =
VAR _min =
    MIN ( 'Calendar'[Date] )
VAR _max =
    MAX ( 'Calendar'[Date] )
VAR _name =
    CALCULATE (
        MAX ( 'Table 1'[Person_Name] ),
        FILTER (
            'Table 1',
            'Table 1'[From_Date] <= _min
                && 'Table 1'[To_Date] >= _max
                && 'Table 1'[Type_Support] = "money"
        )
    )
RETURN
    _name

 

 

smpa01_0-1641400906145.png

 

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

View solution in original post

5 REPLIES 5
smpa01
Super User
Super User

@jelledaems  you can create a measure like this

Measure =
VAR _min =
    MIN ( 'Calendar'[Date] )
VAR _max =
    MAX ( 'Calendar'[Date] )
VAR _name =
    CALCULATE (
        MAX ( 'Table 1'[Person_Name] ),
        FILTER (
            'Table 1',
            'Table 1'[From_Date] <= _min
                && 'Table 1'[To_Date] >= _max
                && 'Table 1'[Type_Support] = "money"
        )
    )
RETURN
    _name

 

 

smpa01_0-1641400906145.png

 

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

@jelledaems  did you try this out yet?

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
jelledaems
Frequent Visitor

 My idea was to first calculate a variable in the measure that will make a list of all dates between 2021-07-01 until 2021-12-31, which is easy to do with the CALENDAR function. 

But then I would also need a list of all dates for which that person has support of money and then use the EXCEPT function to see if there are any dates without support or something... I don't know how to do something like that, so it is hard to explain.

ValtteriN
Super User
Super User

Hi,

Here is one way to do this:

SupportTest =
var _sdate = DATE(2021,7,1)
var _edate = DATE(2021,12,31) return

IF(SELECTEDVALUE('Table (3)'[Type_Support])="money"&&SELECTEDVALUE('Table (3)'[From_Date])<=_sdate&&SELECTEDVALUE('Table (3)'[To_Date])>=_edate,1,0)

Example in table:
ValtteriN_0-1641372570654.png


Now we can use this measure to filter the table to get the names:

ValtteriN_1-1641372612167.png

 

I hope this helps and if it does consider accepting this as a solution and giving the post a thumbs up!

Disclaimer, If you want to construct the period from multiple rows (e.g. Joe could have first stupport from 1.7.2021 to 1.8.2021 and then 1.8.2021 to 1.1.2022 things will get more complicated.)




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

Proud to be a Super User!




Hi, thank you for your quick reply. The only thing is - and that might be my fault for not mentioning it - but you can have monthly money support as well, for example:

 

Joe W.money2021-06-012021-07-01
Joe W.money2021-07-012021-08-02
Joe W.money2021-08-022021-10-15
Joe W.money2021-10-152022-02-02

 

In this example Joe W. should also come out of this list, because he has not interrupted money support from 2021-07-01 until at least 2021-12-31 - even though it is in mutiple records. And that is actually the thing I am struggling with. Sorry for not making this more clear in my previous example.

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.

Top Solution Authors