cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

## 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
Community Support

Hi @nhol,

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

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 ]))

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.
4 REPLIES 4
Community Support

Hi @nhol,

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

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 ]))

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

Resolver I

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

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.