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
dipique
New Member

Column formula to expand a date range by month instead of by day

I currently have a table with a list of contracts, start date, and termination date. I want a chart that shows active active contracts by month. So if my current data is:

 

Contract NameStart DateTermination Date
Customer 13/1/20186/30/2018
Customer 25/1/20189/30/2018
Customer 32/1/201810/31/2018

 

I need to be able to produce a table like this:

 

MonthActive Contracts
Jan 20180
Feb 20181
Mar 20182
Apr 20182
May 20183
Jun 20183
Jul 20182
Aug 20182
Sep 20182
Oct 20181
Nov 20180

 

The summarizing is all simple; the real problem was expanding the date ranges to display the months in between.

 

I found that I can use a formula to expand the range into the dates between by creating a new column with the custom formula:

 

{[Start Date]..[Termination Date]}

I then group by month to produce the visualization I want. The problem is that contracts last several years, which means that (for example) 200 contracts with a length of 10 years each (or 3,650 days) results in 730,000 records. This quickly gets out of hand, and performance is definitely an issue.

 

I would like to modify the formula to expand the date range by month instead of by day. For example, it could produce a list of only the first day of every month instead of every day in every month. I could filter the table, but that has all the same issues I am trying to deal with.

 

Help please! Thank you!

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

Please see my Open Tickets Quick Measure:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Thank you so much! This got me far enough to get a solution working. I created the calendar using this formula:

 

 

Program Active Months = FILTER(CALENDAR(DATE(2018,1,1),DATE(2025,12,31)),AND(DAY([Date])=1, TODAY()>=[Date]))

 

 

This got me the first day of every month between the date of our product launch and the current date.

 

Then, I used this to produce the table I wanted which showed me enrollee count by client and month:

 

Active Enrollees = 
VAR tmpTable =  
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            Enrollment,
            'Program Active Months'
        ),
        [Date] >= [Effective_Date__c] &&
        [Date] <= Enrollment[End Date]
    ),
    "Id", Enrollment[Id],
    "Date", [Date],
    "Account", [Account Name]
)
RETURN GROUPBY(tmpTable,[Date],[Account],"Count",COUNTX(CURRENTGROUP(),[Id]))

Now I have just what I need! Thank again for your help.

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

Please see my Open Tickets Quick Measure:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you so much! This got me far enough to get a solution working. I created the calendar using this formula:

 

 

Program Active Months = FILTER(CALENDAR(DATE(2018,1,1),DATE(2025,12,31)),AND(DAY([Date])=1, TODAY()>=[Date]))

 

 

This got me the first day of every month between the date of our product launch and the current date.

 

Then, I used this to produce the table I wanted which showed me enrollee count by client and month:

 

Active Enrollees = 
VAR tmpTable =  
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            Enrollment,
            'Program Active Months'
        ),
        [Date] >= [Effective_Date__c] &&
        [Date] <= Enrollment[End Date]
    ),
    "Id", Enrollment[Id],
    "Date", [Date],
    "Account", [Account Name]
)
RETURN GROUPBY(tmpTable,[Date],[Account],"Count",COUNTX(CURRENTGROUP(),[Id]))

Now I have just what I need! Thank again for your help.

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.