Forum Discussion

saipawar's avatar
saipawar
Helper IV
2 years ago
Solved

Dynamic text field based on current date

Hi, 

 

I want to display "currently you are in <Phase 1>, 22 days to go for the event"

- Currently means today's date

- <Phase 1> will be picked from a lookup up below

- countdown wrt to Phase 3 date

PhaseDate 
Phase 1Monday, June 12,2023 
Phase 2Tuesday, August 1,2023 
Phase 3Tuesday, October 17, 2023

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi saipawar ,

     

    Thanks for the reply from PhilipTreacy , like he said, I do not quite understand your needs, I can only do what I can to help you.

     

    Based on the table you provided, I am not sure why today is part of phase 1 and why it is 22 days.

     

    My understanding is this:

     

    First determine the phase you currently belong to based on today is date, then calculate the number of days between today and Phase 3.

     

    If today is date is earlier than Phase 1 then it belongs to Phase 1, if today is date is earlier than Phase 2 then it belongs to Phase 2, if today is date is earlier than Phase 3 then it belongs to Phase 3.

     

    I modified the example data as follows:

    Phase

    Date

    Phase 1

    6/12/2024

    Phase 2

    8/1/2024

    Phase 3

    10/17/2024

     

    First, create a measure to calculate the phase to which the current date belongs:

     

    Current Phase =
    VAR TodayDate =
        TODAY ()
    RETURN
        IF (
            TodayDate
                < CALCULATE (
                    MAX ( 'Phases'[Date] ),
                    FILTER ( 'Phases', 'Phases'[Phase] = "Phase 1" )
                ),
            "Phase 1",
            IF (
                TodayDate
                    < CALCULATE (
                        MAX ( 'Phases'[Date] ),
                        FILTER ( 'Phases', 'Phases'[Phase] = "Phase 2" )
                    ),
                "Phase 2",
                "Phase 3"
            )
        )

     

     

    Next, calculate the date interval between today and the Phase 3 date:

     

    Countdown to Phase 3 =
    VAR Phase3Date =
        CALCULATE (
            MAX ( 'Phases'[Date] ),
            FILTER ( 'Phases', 'Phases'[Phase] = "Phase 3" )
        )
    RETURN
        DATEDIFF ( TODAY (), Phase3Date, DAY )

     

     

    Then, apply dynamic text formatting, which will change dynamically based on today is date:

     

    Dynamic Text =
    "Currently, you are in " & [Current Phase] & ", "
        & ABS ( [Countdown to Phase 3] ) & " days to go for the event."

     

     

    Finally, the Dynamic Text is dragged to the card visual object for display, and the page visualization looks like the following:

     

    The pbix file is attached.

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Yang
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

2 Replies

  • Hi saipawar 

     

    Your request is too vague.

     

    How do we know what phase has been seelcted?

     

    Where do you want this information displayed?  In a card visual?

     

    If the countodwn is wrt to the Phase3 date, and you are in Phase 1, based on your table, there would be more than 22 days to go.

     

    Please provide more information and answers to the above.

     

    Regards

     

    Phil

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi saipawar ,

     

    Thanks for the reply from PhilipTreacy , like he said, I do not quite understand your needs, I can only do what I can to help you.

     

    Based on the table you provided, I am not sure why today is part of phase 1 and why it is 22 days.

     

    My understanding is this:

     

    First determine the phase you currently belong to based on today is date, then calculate the number of days between today and Phase 3.

     

    If today is date is earlier than Phase 1 then it belongs to Phase 1, if today is date is earlier than Phase 2 then it belongs to Phase 2, if today is date is earlier than Phase 3 then it belongs to Phase 3.

     

    I modified the example data as follows:

    Phase

    Date

    Phase 1

    6/12/2024

    Phase 2

    8/1/2024

    Phase 3

    10/17/2024

     

    First, create a measure to calculate the phase to which the current date belongs:

     

    Current Phase =
    VAR TodayDate =
        TODAY ()
    RETURN
        IF (
            TodayDate
                < CALCULATE (
                    MAX ( 'Phases'[Date] ),
                    FILTER ( 'Phases', 'Phases'[Phase] = "Phase 1" )
                ),
            "Phase 1",
            IF (
                TodayDate
                    < CALCULATE (
                        MAX ( 'Phases'[Date] ),
                        FILTER ( 'Phases', 'Phases'[Phase] = "Phase 2" )
                    ),
                "Phase 2",
                "Phase 3"
            )
        )

     

     

    Next, calculate the date interval between today and the Phase 3 date:

     

    Countdown to Phase 3 =
    VAR Phase3Date =
        CALCULATE (
            MAX ( 'Phases'[Date] ),
            FILTER ( 'Phases', 'Phases'[Phase] = "Phase 3" )
        )
    RETURN
        DATEDIFF ( TODAY (), Phase3Date, DAY )

     

     

    Then, apply dynamic text formatting, which will change dynamically based on today is date:

     

    Dynamic Text =
    "Currently, you are in " & [Current Phase] & ", "
        & ABS ( [Countdown to Phase 3] ) & " days to go for the event."

     

     

    Finally, the Dynamic Text is dragged to the card visual object for display, and the page visualization looks like the following:

     

    The pbix file is attached.

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Yang
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!