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
nhol
Advocate II
Advocate II

Calculating days in a period

Hi,

 

While designing a sales rep incentive model I came across a request to calculate how many days passed until today from the overall days that are in the period.

The periods are based on Trimesters which means:

January to April is T1

May to August is T2

September to December is T3

For any given year.

 

So the idea is to know how many days have been gone since the beginning of the Trimester until today out of the total days for this Trimester and the result is in %.

For example if we are on July 7, then the DAX formula needs to calculate how many days passed since May 1st until July 7th, which is 68 (if my calculation is correct) and divide that by days in T2 which is supposed to be 123. That should give us the result of 55%.

 

Any idea how to resolve this?

 

The request didn’t specify if it should count only for working days so for the sake of simplicity I would calculate calendar days

 

Thanks!

NH

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @nhol,

 

Assume raw data looks like below, you can create a measure below: 

 

q5.PNG

 

 

Measure = var maxmonth=CALCULATE(MAX('Table1'[Month]),FILTER(ALL(Table1),'Table1'[Trimesters ]=MAX('Table1'[Trimesters ])))
var minmonth= CALCULATE(MIN('Table1'[Month]),FILTER(ALL(Table1),'Table1'[Trimesters ]=MAX('Table1'[Trimesters ])))
return

IF(MONTH(TODAY())>= minmonth && MONTH(TODAY())<=maxmonth,DATEDIFF(DATE(YEAR(TODAY()),minmonth,"1"),TODAY(),DAY)/MAX('Table1'[Trimesters ]))

 

q4.PNG

 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
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
v-qiuyu-msft
Community Support
Community Support

Hi @nhol,

 

Assume raw data looks like below, you can create a measure below: 

 

q5.PNG

 

 

Measure = var maxmonth=CALCULATE(MAX('Table1'[Month]),FILTER(ALL(Table1),'Table1'[Trimesters ]=MAX('Table1'[Trimesters ])))
var minmonth= CALCULATE(MIN('Table1'[Month]),FILTER(ALL(Table1),'Table1'[Trimesters ]=MAX('Table1'[Trimesters ])))
return

IF(MONTH(TODAY())>= minmonth && MONTH(TODAY())<=maxmonth,DATEDIFF(DATE(YEAR(TODAY()),minmonth,"1"),TODAY(),DAY)/MAX('Table1'[Trimesters ]))

 

q4.PNG

 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank You!

This was excellent only if I had all Months and Trimesters numbers already in my database.

However, the situation is that my dataset includes YTD data up until the prior month. So for example if we are in July, the dataset is updated only with January to June (1 to 6 ) months of data.

Therefore the min and max if function doesn't work here.

 

Any other idea?

 

Best,

NH

 

 

Hi @nhol

 

can you share your sample data.

Unfortunately not but I think I got it to work in a simplify way:

 

MSR_%DatesinPeriod =
IF(Sales[MSR_TrimesterNumber] = "1" , DATEDIFF(DATE(CALCULATE(MAX(Sales[Year])) , 1 , 1) , TODAY() , DAY ) / 120 ,
IF(Sales[MSR_TrimesterNumber] = "2" , DATEDIFF(DATE(CALCULATE(MAX(Sales[Year])) , 5 , 1) , TODAY() , DAY ) / 123 ,
IF(Sales[MSR_TrimesterNumber] = "3" , DATEDIFF(DATE(CALCULATE(MAX(Sales[Year])) , 8 , 1) , TODAY() , DAY ) / 122 , 0 )))

 

Thanks all!

NH

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.