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

datesinperiod with two different date fields (SUMIFS Exclel) not working

Hello there,

 

I'm trying to convert a working Excel SUMIFS formula in to DAX.

Am not very experienced in DAX user.

 

What i'm trying to do is calculate a sum for a throughput time in seconds for a combination of filters on two diffenrent date fields.

In my Reservations table i have a location and the value Time service (minutes) which indicates the time needed for a certain service.

I now want to calculate how much work i can expect for the next 56 days for a locaction and product, or overall.

I want to calculate the amount of time [Time service] for [Created date] equal or earlier than any chosen date and for [Plan delivery date] in the next 56 days from the chosen date.

 

Using a DimDate and DATESINPERIOD finctios but can't seem to make it work. The results are missing dates that are not in the Reservations table.

 

 

CALCULATE(SUM(Reservations[Time service]),DATESINPERIOD(Date[Date],LASTDATE(Reservations[Creatted date]),-1,year),ALL(Date),DATESINPERIOD(Date[Date],LASTDATE(Reservations[Plan delivery date]),56,day))

 

 

Here a sample of the data table [Reservations].

 

Example    
     
LocationProductCreated datePlan delivery DateTime service
ax1-2-20182-2-2018100
ay1-2-20182-2-201850
az1-2-201816-3-201875
ax1-2-20185-4-201835
ay5-2-20182-2-2018100
az7-2-20182-2-201850
ax7-2-201816-3-201875
ay8-2-20185-4-201835
bz3-2-20182-2-2018100
by3-2-20182-2-201850
bx3-2-201816-3-201875
bz3-2-20185-4-201835
bz7-2-20182-2-2018100
bx9-2-20182-2-201850
by9-2-201816-3-201875
bx10-2-20185-4-201835

 

Hope someone can help me!!

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

try  this

Measure 3 = 
VAR SelectedDate = SELECTEDVALUE(Date_Dim[Date])
VAR Workload =
    FILTER (
        'Reservations',
        'Reservations'[Plan_Delivery_Date]
            < SelectedDate + 56
            && 'Reservations'[Plan_Delivery_Date] >= SelectedDate
            && 'Reservations'[Created_Date] <= SelectedDate
    )
RETURN
    SUMX ( Workload, [Time_service] )

it works if both of the date joins between Reservations and Dim_Date are inactive



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

8 REPLIES 8
v-yuta-msft
Community Support
Community Support

Hi Ruud_K ,

 

"

I now want to calculate how much work i can expect for the next 56 days for a locaction and product, or overall.

I want to calculate the amount of time [Time service] for [Created date] equal or earlier than any chosen date and for [Plan delivery date] in the next 56 days from the chosen date.

"

 

<--- Which relationship between date table and reservation table, could you clarify more details about your expected result?

 

Regards,

Jimmy Tao

Anonymous
Not applicable

Hi Jimmy,

 

Its actually very simple.

I have the two date fields linked to my Date table.

The link for [Plan delivery date] is active. The other inactive since i can only choose one active realitionship. 

 

The expected results and the excel formulas are as followed:

 

Example                    
Table Reservations       Expected result          
LocationProductCreated datePlan delivery DateValue(Created date)Vlaue (Plan)Time service LocationDateWorkload_56 day         
ax1-2-20182-2-201843132,0043133,00100  a1-2-2018225         
ay1-2-20182-2-201843132,0043133,0050  a2-2-2018225         
az1-2-201816-3-201843132,0043175,0075  a3-2-201875         
ax1-2-20185-4-201843132,0043195,0035  a4-2-201875         
ay5-2-20186-2-201843136,0043137,00100  a5-2-2018175         
az7-2-20189-2-201843138,0043140,0050  a6-2-2018175         
ax7-2-201816-3-201843138,0043175,0075  a7-2-2018200         
ay8-2-20185-4-201843139,0043195,0035  a8-2-2018200         
bz3-2-20182-2-201843134,0043133,00100  b1-2-20180         
by3-2-20182-2-201843134,0043133,0050  b8-2-2018325         
bx3-2-201816-3-201843134,0043175,0075  b15-2-2018470         
bz3-2-20185-4-201843134,0043195,0035  b22-2-2018220         
bz7-2-201818-2-201843138,0043149,00250  b1-3-2018220         
bx9-2-20182-2-201843140,0043133,0050  b8-3-2018220         
by9-2-201816-3-201843140,0043175,0075  b15-3-2018220         
bx10-2-20185-4-201843141,0043195,0035  b22-3-201870         
                     
                     
 SUMIFS =SOMMEN.ALS($K$11:$K$26;$H$11:$H$26;">="&O11;$H$11:$H$26;"<"&O11+56;$G$11:$G$26;"<="&O11;$E$11:$E$26;N11)         
                     
 DAX CALCULATE(SUM(Reservations[Time service]),DATESINPERIOD(Date[Date],LASTDATE(Reservations[Creatted date]),-1,year),ALL(Date),DATESINPERIOD(Date[Date],LASTDATE(Reservations[Plan delivery date]),56,day))
                     
Stachu
Community Champion
Community Champion

I want to calculate the amount of time [Time service] for [Created date] equal or earlier than any chosen date and for [Plan delivery date] in the next 56 days from the chosen date.

 

this should work after claryfing where 'any chosen date' is coming from, now it's hardcoded to 2018-03-15 in SelectedDate variable. Is it supposed to come from Plan Delivery Date? the dates in your Excel example are not matching with it

Measure =
VAR SelectedDate =
    DATE ( 2018, 3, 15 )
VAR Workload =
    FILTER (
        'Table',
        'Table'[Plan delivery Date]
            < SelectedDate + 56
            && 'Table'[Plan delivery Date] >= SelectedDate
            && 'Table'[Created date] <= SelectedDate
    )
RETURN
    SUMX ( Workload, [Time service] )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

The date came from a Dimension table from 2010 to 2099 called Date on fieldname date (Date[Date])

Anonymous
Not applicable

Thans for the input.

Formula is working but does not give the right results.

 

To clarify.

I would like to make a vusual where i can show the known planned workload over an time period of say 16 months.

This means the sum of the values [Time_service] for all the [Created_Date] equal or older than 2016;2;16 and all the [Plan_Delivery_Date] equal or 56 days after 2016;2;16.

 

I have used the following Formula:

Measure 3 = VAR SelectedDate =
DATE (2016;2;16)
VAR Workload =
    FILTER (
        'Reservations';
        'Reservations'[Plan_Delivery_Date]
            < SelectedDate + 56
            && 'Reservations'[Plan_Delivery_Date] >= SelectedDate
            && 'Reservations'[Created_Date] <= SelectedDate     )
RETURN
    SUMX ( Workload; [Time_service] )

 

My Datamodel is as follows:

Data model.JPG

 

The results from the formula do not match the expected values.

What do i need to alter in the DAX formula.

 

PS. I would prefer a formula in which the Dat_Dim is used in stead of a fixed date. Since i want a visualisation on more than 1 date

Stachu
Community Champion
Community Champion

try  this

Measure 3 = 
VAR SelectedDate = SELECTEDVALUE(Date_Dim[Date])
VAR Workload =
    FILTER (
        'Reservations',
        'Reservations'[Plan_Delivery_Date]
            < SelectedDate + 56
            && 'Reservations'[Plan_Delivery_Date] >= SelectedDate
            && 'Reservations'[Created_Date] <= SelectedDate
    )
RETURN
    SUMX ( Workload, [Time_service] )

it works if both of the date joins between Reservations and Dim_Date are inactive



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Hey @Stachu

 

Works perfectly. Thanks for this.

Could i bother anyone for a extra question on this problem.

 

Is it possible to get the values but not for 56 days in betweek but for 40 workdays.

The date table has a workday indicator (J/N)  named [Workday_ind] and a Workdat value (1 or 0) named [Workday_value]

 

 

 

Stachu
Community Champion
Community Champion

try this, you may play with >=/> to get what you need exactly

Measure 3 = 
VAR SelectedDate = SELECTEDVALUE(Date_Dim[Date])
VAR OnlyWorking = FILTER(ALL(Date_Dim[Date], Date_Dim[Workday_value]), Date_Dim[Workday_value]<>0 && Date_Dim[Date]>SelectedDate)
VAR RollingWD = ADDCOLUMNS(OnlyWorking,"RollingWD",RANKX(OnlyWorking, [Date], ,ASC))
VAR NextDate = CALCULATE(MAX(Date_Dim[Date]),FILTER(RollingWD,[RollingWD]=40))
VAR Workload =
    FILTER (
        'Reservations',
        'Reservations'[Plan_Delivery_Date]
            <= NextDate
            && 'Reservations'[Plan_Delivery_Date] >= SelectedDate
            && 'Reservations'[Created_Date] <= SelectedDate
    )
RETURN
    SUMX ( Workload, [Time_service] )

EDIT
this may work even better:

Measure 3 = 
VAR SelectedDate = SELECTEDVALUE(Date_Dim[Date])
VAR OnlyWorking = FILTER(ALL(Date_Dim[Date], Date_Dim[Workday_value]), Date_Dim[Workday_value]<>0 && Date_Dim[Date]>SelectedDate)
VAR Top40WD = TOPN(40,OnlyWorking,[Date],ASC)
VAR NextDate = CALCULATE(MAX(Date_Dim[Date]),Top40WD)
VAR Workload =
    FILTER (
        'Reservations',
        'Reservations'[Plan_Delivery_Date]
            < NextDate
            && 'Reservations'[Plan_Delivery_Date] >= SelectedDate
            && 'Reservations'[Created_Date] <= SelectedDate
    )
RETURN
    SUMX ( Workload, [Time_service] )

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

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.