Forum Discussion

darko861's avatar
darko861
Icon for Resolver II rankResolver II
2 years ago
Solved

Select Correct Date Range in Card

Hi Community,

 

I have the following pbix file.

https://www.dropbox.com/scl/fi/30tn682n98oacda3wu4y4/TestData.pbix?rlkey=j3si9f97vgx9i3268tsk5jhhd&dl=0

 

It's a test dataset with mock values. I want to display the time period for the latest test that has been run in a card visual. In this case, the test was performed on 2023-09-01.

 

 

 

 

The card visual says that the test belongs to the time frame Train 9 - 6/23/2023 - 8/31/2023. This is incorrect. It should belong to the time frame Train 10 - 9/1/2023 - 11/10/2023 as shown in the disconnected table TrainDate below.

 

 

The measure I have used is incorrect. I would really appreciate it if you could tweak the measure so that it shows the correct output but also that it's dynamic when a new test is performed. E.g if a test is performed in August then it should be updated accordingly to the Train schedule.

 

incorrect measure:

TrainCyclePeriodAuto2 =

VAR CurrentDate = MAXX(FILTER(ALL(DimDate),DimDate[Latest Date]="Latest"),DimDate[Date])

RETURN
 
 MAXX(FILTER(
        TrainDate,
            CurrentDate >= MIN (TrainDate[StartDate] )
            && CurrentDate <= MAX(TrainDate[EndDate])
            &&CurrentDate >= MIN ( TrainDate[StartDate])
            && CurrentDate <= MAX ( TrainDate[EndDate] )),TrainDate[name] & " - " & TrainDate[StartDate] &" - " &TrainDate[EndDate])

 

Thanks a lot!

  • Hi Guys,

     

    It wasn't as straightforward as one might think, but I managed to tweak the DAX using this measure:

     

    Test =
    VAR __dt = MAXX(FILTER(ALL(DimDate),DimDate[Latest Date]="Latest"),DimDate[Date])
    RETURN
        MAXX(
            FILTER(
                VALUES( TrainDate ),
                TrainDate[startdate] <= __dt && __dt < TrainDate[enddate]
            ),TrainDate[name] & " - " & TrainDate[StartDate] &" - " &TrainDate[EndDate])
     
    It works really great now, and the card visual will get updated dynamically as soon as a new test is performed with a different timeframe.
     

1 Reply

  • Hi Guys,

     

    It wasn't as straightforward as one might think, but I managed to tweak the DAX using this measure:

     

    Test =
    VAR __dt = MAXX(FILTER(ALL(DimDate),DimDate[Latest Date]="Latest"),DimDate[Date])
    RETURN
        MAXX(
            FILTER(
                VALUES( TrainDate ),
                TrainDate[startdate] <= __dt && __dt < TrainDate[enddate]
            ),TrainDate[name] & " - " & TrainDate[StartDate] &" - " &TrainDate[EndDate])
     
    It works really great now, and the card visual will get updated dynamically as soon as a new test is performed with a different timeframe.