Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
mdaatifraza5556
Super User
Super User

calculate datediff (Total days) and it should not be affected by another slicer

Good morning,

I am facing an issue while calculating the total days between the selected dates using the range slicer.

The relationship between the tables is bidirectional, with the Reports table having a one-to-many relationship with the Reason table.

Slicers I am using:

  • Location, Reason Name, and Start Time from the Reason table
  • Grade from the Reports table

The below DAX formula I am using works fine, it is not affected by Location and Reason when I set the date in the range slicer. However, it is affected by Grade i want that that it it should not be affected by Grade as well..

Please help me resolve this issue.

Thank you



Hrs_In =
VAR StartDate =
    CALCULATE(
        MIN(tblDownTimeReport[StartTime]),
        CROSSFILTER(tblDownTimeReport[Id], DownTimeReportReason[DownTimeId], NONE),
        REMOVEFILTERS(tblDownTimeReport[GradeCode])
    )

VAR EndDate =
    CALCULATE(
        MAX(tblDownTimeReport[StartTime]),
        CROSSFILTER(tblDownTimeReport[Id], DownTimeReportReason[DownTimeId], NONE),
        REMOVEFILTERS(tblDownTimeReport[GradeCode])
    )

 
VAR MonthsInRange =
    SELECTCOLUMNS(
        FILTER(
            ALL(tblDownTimeReport),
            tblDownTimeReport[StartTime] >= StartDate &&
            tblDownTimeReport[StartTime] <= EndDate
        ),
        "MonthStart", tblDownTimeReport[StartTime]
    )

 
VAR MinDate = MINX(MonthsInRange, [MonthStart])
VAR MaxDate = MAXX(MonthsInRange, [MonthStart])

 
VAR _Days = DATEDIFF(MinDate, MaxDate, DAY) + 1

RETURN _Days






 
 
1 ACCEPTED SOLUTION

@mdaatifraza5556 Update it using ALL

dax
Hrs_In =
VAR StartDate =
CALCULATE(
MIN(tblDownTimeReport[StartTime]),
CROSSFILTER(tblDownTimeReport[Id], DownTimeReportReason[DownTimeId], NONE),
ALL(tblDownTimeReport[GradeCode])
)

VAR EndDate =
CALCULATE(
MAX(tblDownTimeReport[StartTime]),
CROSSFILTER(tblDownTimeReport[Id], DownTimeReportReason[DownTimeId], NONE),
ALL(tblDownTimeReport[GradeCode])
)

VAR MonthsInRange =
SELECTCOLUMNS(
FILTER(
ALL(tblDownTimeReport),
tblDownTimeReport[StartTime] >= StartDate &&
tblDownTimeReport[StartTime] <= EndDate
),
"MonthStart", tblDownTimeReport[StartTime]
)

VAR MinDate = MINX(MonthsInRange, [MonthStart])
VAR MaxDate = MAXX(MonthsInRange, [MonthStart])

VAR _Days = DATEDIFF(MinDate, MaxDate, DAY) + 1

RETURN _Days




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

6 REPLIES 6
v-sdhruv
Community Support
Community Support

Hi @mdaatifraza5556 ,
Glad to know you were able to resolve the issue.
If the response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank You

mdaatifraza5556
Super User
Super User

Thank you so much for the reply.
I got my solution.
I was facing the issue due to data modelling.

bhanu_gautam
Super User
Super User

@mdaatifraza5556 , try using

DAX
Hrs_In =
VAR StartDate =
CALCULATE(
MIN(tblDownTimeReport[StartTime]),
CROSSFILTER(tblDownTimeReport[Id], DownTimeReportReason[DownTimeId], NONE),
REMOVEFILTERS(tblDownTimeReport[GradeCode])
)

VAR EndDate =
CALCULATE(
MAX(tblDownTimeReport[StartTime]),
CROSSFILTER(tblDownTimeReport[Id], DownTimeReportReason[DownTimeId], NONE),
REMOVEFILTERS(tblDownTimeReport[GradeCode])
)

VAR MonthsInRange =
SELECTCOLUMNS(
FILTER(
ALL(tblDownTimeReport),
tblDownTimeReport[StartTime] >= StartDate &&
tblDownTimeReport[StartTime] <= EndDate
),
"MonthStart", tblDownTimeReport[StartTime]
)

VAR MinDate = MINX(MonthsInRange, [MonthStart])
VAR MaxDate = MAXX(MonthsInRange, [MonthStart])

VAR _Days = DATEDIFF(MinDate, MaxDate, DAY) + 1

RETURN _Days

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi @bhanu_gautam 
Here are samples, kindly help me with this I think if iIget solved on this, then it will work

below i am providing some sample what i want is. 
I want total days when i am selecting start and end date in range slicer then it gives me total days and that total days should not be affected by grade slicer if selecting any one of the grade

Statrt DateGradeCode
01-03-2025211287
01-03-2025211287
02-03-202584693
02-03-202584693
02-03-202584693
03-03-2025257533
03-03-2025257533
03-03-2025257533
03-03-2025212202
03-03-2025257533
04-03-2025267520
04-03-2025267520
04-03-2025267520
05-03-2025257533

 

@mdaatifraza5556 Update it using ALL

dax
Hrs_In =
VAR StartDate =
CALCULATE(
MIN(tblDownTimeReport[StartTime]),
CROSSFILTER(tblDownTimeReport[Id], DownTimeReportReason[DownTimeId], NONE),
ALL(tblDownTimeReport[GradeCode])
)

VAR EndDate =
CALCULATE(
MAX(tblDownTimeReport[StartTime]),
CROSSFILTER(tblDownTimeReport[Id], DownTimeReportReason[DownTimeId], NONE),
ALL(tblDownTimeReport[GradeCode])
)

VAR MonthsInRange =
SELECTCOLUMNS(
FILTER(
ALL(tblDownTimeReport),
tblDownTimeReport[StartTime] >= StartDate &&
tblDownTimeReport[StartTime] <= EndDate
),
"MonthStart", tblDownTimeReport[StartTime]
)

VAR MinDate = MINX(MonthsInRange, [MonthStart])
VAR MaxDate = MAXX(MonthsInRange, [MonthStart])

VAR _Days = DATEDIFF(MinDate, MaxDate, DAY) + 1

RETURN _Days




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks for your reply, but it is still getting affected by the grade code slicer


at the same time am using this DAX it also working same


 StartDate =
 var start_date = CALCULATE(
     MIN(tblDownTimeReport[StartTime]),
     ALLSELECTED(tblDownTimeReport[StartTime]),  
     ALL(tblDownTimeReport[GradeCode]),  
     CROSSFILTER(tblDownTimeReport[Id], DownTimeReportReason[DownTimeId], NONE)
 )

 VAR end_date =

  CALCULATE(
     MAX(tblDownTimeReport[StartTime]),
     ALLSELECTED(tblDownTimeReport[StartTime]),  
     ALL(tblDownTimeReport[GradeCode]),  
     CROSSFILTER(tblDownTimeReport[Id], DownTimeReportReason[DownTimeId], NONE)
 )

 VAR _days = DATEDIFF(start_date, end_date, DAY)+1

 RETURN
     _days



Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.