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
Anonymous
Not applicable

Using datesbetween

Hello!

I Have the following problem, I have 3 columns: My initial Date, Final Date, and production between the dates, like the folowwing example:

Initial DateFinish DateProduction
01//01/201801//01/2019365


I want to make a measure that divide the production by the numbers of days and list that in my calendar table, with all the dates included.

Thanks in advance!


1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

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

Community Support Team _ Cherie Chen
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
Anonymous
Not applicable

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...

 

AttributteInitial Date- timeFinish Date - timeProduction
A01//01/2018 00:0001//03/2019 12:0060
B01/03/2018 12:0001/04/2018 23:5936



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,


v-cherch-msft
Employee
Employee

Hi @Anonymous

 

Could you tell me if your problem has been solved? If it is,kindly mark the helpful answer as a solution and welcome to share your own solution. More people will benefit from here. If not, please share more details for us so that we could help further on it.

 

Regards,

Cherie

 

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

It worked!
The only thing I changed was instead of using MAX, i Used SUM.
v-cherch-msft
Employee
Employee

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

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

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.