Forum Discussion
DAX Challange - Filtering Date by Difference between Consecutive Dates
- 1 year ago
PowerRobots99 Now you have column in your table as well as you know how to calculate scheduled trans. It is very easy to develop such matrix.
However, here is your desired output:
Code Version 1:ScheduledTrans1 = IF( HASONEVALUE(Data[ReportDate]), MAX(Data[ScheduledTrans]) )Image showing matrix:
Code Version 2:
DistinctScheduledTrans = IF( ISINSCOPE('Data'[ReportDate]), CALCULATE( MINX( 'Data', [ScheduledTrans] ) ), BLANK() )Image showing matrix output version 2:
If you don't want to create a calculated column, then try the below code:
DistinctScheduledTrans_V3 = VAR CurrentReportDate = MAX('Data'[ReportDate]) VAR PreviousDate = CALCULATE( MAX('Data'[ReportDate]), FILTER( ALL('Data'), 'Data'[ReportDate] < CurrentReportDate ) ) VAR DateDiff = DATEDIFF( PreviousDate, CurrentReportDate, DAY ) VAR TransactionIDCount = CALCULATE( COUNT('Data'[Transaction ID]), FILTER( ALL('Data'), 'Data'[TransScheduleCompletionDate] >= PreviousDate + 1 && 'Data'[TransScheduleCompletionDate] <= PreviousDate + DateDiff && 'Data'[ReportDate] = PreviousDate ) ) RETURN IF( ISBLANK(PreviousDate), BLANK(), IF( HASONEVALUE(Data[ReportDate]), TransactionIDCount ) )Here is the desired output:
Hope this helps!!
PowerRobots99 Now you have column in your table as well as you know how to calculate scheduled trans. It is very easy to develop such matrix.
However, here is your desired output:
Code Version 1:
ScheduledTrans1 =
IF(
HASONEVALUE(Data[ReportDate]),
MAX(Data[ScheduledTrans])
)
Image showing matrix:
Code Version 2:
DistinctScheduledTrans =
IF(
ISINSCOPE('Data'[ReportDate]),
CALCULATE(
MINX(
'Data',
[ScheduledTrans]
)
),
BLANK()
)
Image showing matrix output version 2:
If you don't want to create a calculated column, then try the below code:
DistinctScheduledTrans_V3 =
VAR CurrentReportDate = MAX('Data'[ReportDate])
VAR PreviousDate =
CALCULATE(
MAX('Data'[ReportDate]),
FILTER(
ALL('Data'),
'Data'[ReportDate] < CurrentReportDate
)
)
VAR DateDiff =
DATEDIFF(
PreviousDate,
CurrentReportDate,
DAY
)
VAR TransactionIDCount =
CALCULATE(
COUNT('Data'[Transaction ID]),
FILTER(
ALL('Data'),
'Data'[TransScheduleCompletionDate] >= PreviousDate + 1 &&
'Data'[TransScheduleCompletionDate] <= PreviousDate + DateDiff &&
'Data'[ReportDate] = PreviousDate
)
)
RETURN
IF(
ISBLANK(PreviousDate),
BLANK(),
IF(
HASONEVALUE(Data[ReportDate]),
TransactionIDCount
)
)
Here is the desired output:
Hope this helps!!