cancel
Showing results for 
Search instead for 
Did you mean: 
Geeks_D

Display Date Difference Count in {Days ago, Weeks ago, Month ago, etc}

I will be using the With Function and Nested If in PowerApps for this solution, The With function in PowerFx is used to evaluate a formula with one or multiple variables to produce a result. The function has the ability to compute a value and/or carry out operations, such as altering data or interacting with a connection. PowerFX Formular: With (Scope, Formula ….) The scope handles the variable/s and the formula to get a result.

Algorithm for this solution:

1. Assign the date difference into the Date Value

2. Nested if to check for different values of the date to get a result in the Label Control

3. Compute the result with different prefixes for each if statement

Power FX code:

 

With({Date:DateDiff(DateValue("31/08/2023"),Today())},// Dividing DateValue // Assign the Date Value to use into a variable 
If(Date=0,"Today",//   Today prefix
If(Date=1,Date&" "&"day"&" "&"ago",// day ago prefix
If((Date>1 And Date<=6),Date&" "&"days"&" "&"ago",// days ago prefix 
If(Date=7,"1 week"&" "&"ago",// 1 week prefix  
If((Date>8 And Date<=30),Round(Value(Date/7),1)&" "&"weeks"&" "&"ago",//weeks ago prefix
If(Date=30 Or Date=31,"1 month ago",//1 month ago prefix 
If((Date>31 And Date<=365),Round(Value(Date/30),0)&" "&"months"&" "&"ago",// Months ago prefix
If(Date>=365,Round(Value(Date/365),1)&" "&"Years"&" "&"ago"// Years ago prefix 
)))))))))