Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

How to categorize time elapsed since a date?

I've been trying to figure this out for a day or so now. Some messages on this forum have gotten me closer but I'm still not quite there. What I've got is a table (obviously) full of rows (obvious...
  • MFelix's avatar
    8 years ago

    Hi Anonymous,

     

    You can create the column in M language or Dax then just use this column to make you visuals

     

     

     

    M Language (query editor)
    if Duration.Days(Date.From(DateTime.LocalNow()) - [Date]) <= 10 then "10 days ago" else
    if Duration.Days(Date.From(DateTime.LocalNow()) - [Date]) > 10 and Duration.Days(Date.From(DateTime.LocalNow()) - [Date]) <= 20 then "20 days ago" else
    if Duration.Days(Date.From(DateTime.LocalNow()) - [Date]) > 20 and Duration.Days(Date.From(DateTime.LocalNow()) - [Date]) <= 30 then "30 days ago" else
    "> 30 day"
    
    
    
    DAX
    
    Bin =
    VAR Date_Select =
        DATEDIFF ( Table1[Date]; TODAY (); DAY )
    RETURN
        SWITCH (
            TRUE ();
            Date_Select <= 10; "10 days ago";
            Date_Select > 10
                && Date_Select <= 20; "20 days ago";
            Date_Select > 20
                && Date_Select <= 31; "30 days ago";
            "> 30 days"
        )

     

     

    Regards,

    MFelix