Expression that simplifies a fraction

How do you create an expression that simplifies a fraction?

For example: if I have two columns [Width] and [Height] having respectively the values 1920 and 1080, how to create the formula of a third column [AspectRatio] which should return the text: "16:9"?

1920/1080 = 16/9

I did not find how to do this under AppSheet, could you help me please?

 
 

 

 

0 3 240
3 REPLIES 3

I believe it may not be very easy to calculate the fraction if there are open ended or unlimited types of aspect ratios. If there are handful of aspect ratios such as 16:9 and 4:3 known beforehand and may be one or two more , we could come up with an expression that converts higher values such as 1920: 1080 into 16:9 and so on.

16:9 is also known as 1.78:1 and 4:3 is also known as 1.33:1. If this proportion where the right hand ratio is always 1 is acceptable , then of course any aspect ratio can be calculated.

Would you please elaborate?

The best would be if I make two virtual columns with both notations, one that returns "4:3" and the other that returns "1.33:1". Then I could create a third virtual column to display:
"4:3 (1.33:1)".

Thank you. Please try in a VC, the following expression. It will give the aspect ratio together as desired by you in the format "4:3 (1.33:1)"

IFS(

AND([Width]*1.000/[Height]*1.000>=1.777, [Width]*1.000/[Height]*1.000<=1.779), "16:9 (1.78:1)",
AND( [Width]*1.000/[Height]*1.000>=1.333, [Width]*1.000/[Height]*1.000<=1.34) , "4:3 (1.33:1)",
AND( [Width]*1.000/[Height]*1.000>=2.37, [Width]*1.000/[Height]*1.000<=2.39) , "21:9 (2.37:1)",
AND( [Width]*1.000/[Height]*1.000>=3.5555, [Width]*1.000/[Height]*1.000<=3.56), "32:9 (3.55:1)"

   )

 

If the two aspect ratios formats are required separately, we will need to break the part "16:9(1.78:1)" in two different expressions such as below

For the (4:3) format:

IFS(

AND([Width]*1.000/[Height]*1.000>=1.777, [Width]*1.000/[Height]*1.000<=1.779), "16:9",
AND( [Width]*1.000/[Height]*1.000>=1.333, [Width]*1.000/[Height]*1.000<=1.34) , "4:3",
AND( [Width]*1.000/[Height]*1.000>=2.37, [Width]*1.000/[Height]*1.000<=2.39) , "21:9",
AND( [Width]*1.000/[Height]*1.000>=3.5555, [Width]*1.000/[Height]*1.000<=3.56), "32:9"

   )

For the (1:33:1) format:

IFS(

AND([Width]*1.000/[Height]*1.000>=1.777, [Width]*1.000/[Height]*1.000<=1.779), "1.78:1",
AND( [Width]*1.000/[Height]*1.000>=1.333, [Width]*1.000/[Height]*1.000<=1.34) , "1.33:1",
AND( [Width]*1.000/[Height]*1.000>=2.37, [Width]*1.000/[Height]*1.000<=2.39) , "2.37:1",
AND( [Width]*1.000/[Height]*1.000>=3.5555, [Width]*1.000/[Height]*1.000<=3.56), "3.55:1"

   )

The expression will give 4 aspect ratios :

modern standard: "1.78:1",

 old standard:"1.33:1", 

ultrawide: "2.37:1" and 

super wide: "3.55:1" 

It should work for most aspect ratio values but may need slight tweak because fractions are not standard at times due to slight different in Width/Height ratio, even though the above expressions have been tested for most common values of Height and Width as the screenshot below shows

[Height] and [Width] are expected to be number type columns and Aspect Ratio is a text column.

Suvrutt_Gurjar_0-1683028216217.png

Edit: Made a minor correction in all expressions. Removed an extra comma(,) in the end. It should not impact the expression evaluation but nonetheless removed it.

 

 

Top Labels in this Space