Forum Discussion
Using datesbetween
- 7 years ago
Hi Anonymous
You may add a column for the sample table:
Days = DATEDIFF(Table[Initial Date],Table[Finish Date],DAY)
Then you may get the measure and show all the dates included.
Divide = CALCULATE ( DIVIDE ( MAX ( Table[Production] ), MAX ( Table[Days] ) ), FILTER ( GENERATE ( 'Calendar', Table ), 'Calendar'[Date] >= Table[Initial Date] && 'Calendar'[Date] <= Table[Finish Date] ) )Regards,
Cherie
Hello!
I discovered a little issue that caused a big problem for me...
Basically the given answers worked really fine if you have only date type, but my data presents DATE and TIME information, so it should be a little like this...
| Attributte | Initial Date- time | Finish Date - time | Production |
| A | 01//01/2018 00:00 | 01//03/2019 12:00 | 60 |
| B | 01/03/2018 12:00 | 01/04/2018 23:59 | 36 |
So, if you follow the DAX formula on the column =
Days = DATEDIFF(Table[Initial Date],Table[Finish Date],DAY)
and the following measure =
Divide =
CALCULATE (
DIVIDE ( SUM ( Table[Production] ), SUM ( Table[Days] ) ),
FILTER (
GENERATE ( 'Calendar', Table ),
'Calendar'[Date] >= Table[Initial Date]
&& 'Calendar'[Date] <= Table[Finish Date]
)
)
The formula works well if you dont show it by atributte, but when I start adding atributte in any visual it gives me the "wrong answer".
What happens is that if I put that in a graph, it will show to me that between day 1 and 3, it produced and average of 20 of atributte A , but that is not true, because it stopped in the middle of the day (it should be 24 per day).
And the same will happen with the Atributte B, it wil show and average of 18 between day 3 and 4 even that started only in the middle of day 3(should be 24 also).
What will happen is that in the "transaction" day (day 3), it shows a production of 20 products A and 18 of product B, given me a total of 38, and not 24 has was suppose to be.
Basically I need to find a way of correcting the number bat also make it link with my calendar table....
The ideia is to have that number in the most acurrate way, in the minutes scale if possible.
Thanks in advance,