henrydhs's avatar
henrydhs
Frequent Visitor
2 years ago
Status:
Done

DAX - Formula contain start and end dates.

Hello, everyone, I need your help.
I have a data matrix with two columns where they contain start and end dates.
I needed to know when we select a date this said it is within the time interval.

An example in the image.

I have already tried to use the dax if function .. but it doesn't work

Thank you

 

7 Comments

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi henrydhs ,

     

    Based on your description, I did simple samples to get the following results:

     

     

     

    Table 2 = CALENDAR(MIN('Table'[StartTime]),MAX('Table'[EndTime]))
    
    range = IF(AND(SELECTEDVALUE('Table 2'[Date])>=MAX('Table'[StartTime]),SELECTEDVALUE('Table 2'[Date])<=MAX('Table'[EndTime])),"within range","")

     

     

    Best regards,
    Community Support Team_ Scott Chang

     

     

     

  • henrydhs's avatar
    henrydhs
    Frequent Visitor

    Hello, Thank you for your help
    but I have a problem. I want to convert the table to data format but I can't
    it gives the following error

     

     

  • henrydhs's avatar
    henrydhs
    Frequent Visitor

    Hello, again I managed to make the formula.
    But now it only shows data if I select the day.
    I wanted to choose a date range if the attribute is valid.
    Example: Check if there is something within the range.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi henrydhs ,

     

    Try using the following expression:

    range = IF(MAX('Table'[StartTime]) <=MAX('Table 2'[Date]) && MAX('Table'[EndTime]) >= MIN('Table 2'[Date]),"within range","")

     

    Best regards,
    Community Support Team_ Scott Chang

     

     

     

  • henrydhs's avatar
    henrydhs
    Frequent Visitor

    Thank you. IT´s working Now.

     

    Now a i have other questions 

     

    - How do I remove the final part of the table "Baixa"?
    - How do I count the number of people? Since it is a measure, I can't use the count formula.

    I needed that when selecting a time period, it would count the number of people to calculate the number of people on "baixa".

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi henrydhs ,

     

    I wrote the ID attribute as a measure for the number of people. You can check the result below:

    Also,you can turn off aggregation via the Totals attribute:

     

     

     

    Measure = CALCULATE(SUMX('Table',[Measure ID]),FILTER('Table','Table'[range]="within range"))

     

     

    Best regards,
    Community Support Team_ Scott Chang