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
Solved! Go to Solution.
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
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
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
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
Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!
User | Count |
---|---|
125 | |
74 | |
65 | |
53 | |
53 |
User | Count |
---|---|
199 | |
104 | |
88 | |
79 | |
77 |