Forum Discussion

esuryahadi's avatar
esuryahadi
Helper I
2 years ago
Solved

due date filter

Hello,

I have table data as follows.

IDContract Name Contractstart dateEnd DateStatus
1ADB22/02/202321/04/2023done
2DFG01/06/202302/10/2023on going
3DFR19/12/202320/02/2024on going
4HGT05/05/202310/10/2023done
5KJR10/10/202312/12/2023on going

 

I want to count the number of days from the end date column with today's date with conditions
< 30 days from Today - color yellow
> today - color red
Done - color black

I've tried with datediff but it hasn't worked.

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi esuryahadi ,

     

    You can also create a measure.

    conditions = SWITCH(TRUE(),
    MAX('Table'[Status])="done","black",
    MAX('Table'[End Date]) > TODAY(),"red",
    DATEDIFF(MAX('Table'[End Date]),TODAY(),DAY)<30,"yellow"
    )

    Setting the Conditional Format.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi esuryahadi ,

     

    I'm sorry I don't quite understand, the IDContract is 3 and 5 when the end date is 2024/2/20 and 2023/12/12. today's date is 2023/11/3 and the end date is greater than today, shouldn't he show red?

     

    According to your description,

    (1) We can create a table.

    Slicer = DATATABLE ( 
        "Type", STRING,
        {
            { "< 30 day"},
            { "> Today" },
            { "Done/Complete" }
        }
    )

    (2) We can create measures. 

    conditions = SWITCH(TRUE(),
    MAX('Table'[Status])="done","black",
    MAX('Table'[End Date]) > TODAY(),"red",
    DATEDIFF(MAX('Table'[End Date]),TODAY(),DAY)<30,"yellow"
    )
    Flag = SWITCH(TRUE(),
    ISFILTERED('Slicer'[Type])=FALSE(),1,
    SELECTEDVALUE('Slicer'[Type])="< 30 day" && [conditions]="yellow",1,
    SELECTEDVALUE('Slicer'[Type])="> Today" && [conditions]="red",1,
    SELECTEDVALUE('Slicer'[Type])="Done/Complete" && [conditions]="black",1,0)

    (3) Setting the conditional format and filtering [Flag=1] as a visual object.

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.

10 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi esuryahadi ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) My test data is the same as yours.

    (2) We can create a measure. 

    conditions = SWITCH(TRUE(),
    MAX('Table'[Status])="done","black",
    MAX('Table'[End Date]) > TODAY(),"red",
    DATEDIFF(MAX('Table'[End Date]),TODAY(),DAY)<30,"yellow"
    )

    (3) Then the result is as follows.

     

     

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

    • esuryahadi's avatar
      esuryahadi
      Helper I

      Thank you.

       This my data. 

      Sorry i try to attactment file csv and pbix is fail.

      No WBSIndex TitleNo Contract Total USD Start DateEnd DateStatus
      C8000006System WTP 3456 $3,45 21/10/201923/10/2019Done
      C8000007Constrution WTP2987 $1,25 21/10/202023/10/2021Done
      C8000008Upgrading Submarine Hose876 $1,25 01/10/202302/11/2023On Going
      C8000009Main Gathering Station7409 $0,13 30/10/202301/11/2023On Going
      C8000010Upgrading Ring Main1928 $0,17 24/02/202027/02/2020Done
      C8000011Install New Oil Trunkline23 $0,14 02/10/202301/12/2023On Going
      C8000012System Cathodic Protection 923 $0,41 01/10/202301/12/2023On Going
      C8000013Intertank Pump 600 92 $0,06 19/09/202320/10/2023On Going
      C8000014Handheld Oil Analyzer8634 $104,32 20/10/202303/01/2024On Going

       

      No WBSIndex TitleNo Contract Total USD Start DateEnd DateStatus
      C8000006System WTP 3456 $3,45 ################Done
      C8000007Constrution WTP2987 $1,25 ################Done
      C8000008Upgrading Submarine Hose876 $1,25 ################On Going
      C8000009Main Gathering Station7409 $0,13 ################On Going
      C8000010Upgrading Ring Main1928 $0,17 ################Done
      C8000011Install New Oil Trunkline23 $0,14 ################On Going
      C8000012System Cathodic Protection 923 $0,41 ################On Going
      C8000013Intertank Pump 600 92 $0,06 ################On Going
      C8000014Handheld Oil Analyzer8634 $104,32 ################On Going
    • esuryahadi's avatar
      esuryahadi
      Helper I

      Hi, Sorry i have problem about my data.

      But so far my data is same.

      after i try you code, still have wrong 

      in IDContract 3 and 5 shouldn't not red. 

      and i want to visual like pic 

       

      Very sorry if my Language is bad

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi esuryahadi ,

         

        I'm sorry I don't quite understand, the IDContract is 3 and 5 when the end date is 2024/2/20 and 2023/12/12. today's date is 2023/11/3 and the end date is greater than today, shouldn't he show red?

         

        According to your description,

        (1) We can create a table.

        Slicer = DATATABLE ( 
            "Type", STRING,
            {
                { "< 30 day"},
                { "> Today" },
                { "Done/Complete" }
            }
        )

        (2) We can create measures. 

        conditions = SWITCH(TRUE(),
        MAX('Table'[Status])="done","black",
        MAX('Table'[End Date]) > TODAY(),"red",
        DATEDIFF(MAX('Table'[End Date]),TODAY(),DAY)<30,"yellow"
        )
        Flag = SWITCH(TRUE(),
        ISFILTERED('Slicer'[Type])=FALSE(),1,
        SELECTEDVALUE('Slicer'[Type])="< 30 day" && [conditions]="yellow",1,
        SELECTEDVALUE('Slicer'[Type])="> Today" && [conditions]="red",1,
        SELECTEDVALUE('Slicer'[Type])="Done/Complete" && [conditions]="black",1,0)

        (3) Setting the conditional format and filtering [Flag=1] as a visual object.

        Best Regards,

        Neeko Tang

        If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi esuryahadi ,

     

    You can also create a measure.

    conditions = SWITCH(TRUE(),
    MAX('Table'[Status])="done","black",
    MAX('Table'[End Date]) > TODAY(),"red",
    DATEDIFF(MAX('Table'[End Date]),TODAY(),DAY)<30,"yellow"
    )

    Setting the Conditional Format.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi esuryahadi ,

         

        I can't access the link you shared, it seems to have no permissions. Please re-share it.


        Referring to my second reply, you can create the measure and then set the conditional format. Refer my pbix file.

        May I ask if you have tried the code I provided? If the output does not match your expected results, please show your input data and expected results in detail.

         

         conditions = SWITCH(TRUE(),
        MAX('YourTableName'[Status])="done","black",
        MAX('YourTableName'[End Date]) > TODAY(),"red",
        DATEDIFF(MAX('YourTableName'[End Date]),TODAY(),DAY)<30,"yellow"
        )

         

         

        Best Regards,

        Neeko Tang

        If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.