Forum Discussion
Need help with Calculated Column
- 5 years ago
Hi, gauravnarchal
When there is a description of the desired output and requirements and condition judgments, then the solution can be obtained earlier.
try to create a measure like this:
_Result = var _is9=DATEDIFF('Table2'[returndate],'Table2'[Shipdate],DAY)*'Table2'[NumberOfItems] var _not9=DATEDIFF('Table2'[Shipdate],'Table2'[returndate],DAY)*'Table2'[NumberOfItems] var _extract1=CONVERT(LEFT(RELATED(Table1[SerialNumber]),1),INTEGER) var _nonconverted=ISERROR(CONVERT(LEFT(RELATED(Table1[SerialNumber]),1),INTEGER)) var _startOfNum=IF(_nonconverted,"Error",IF(_extract1=9,FORMAT(_is9,"General Number"),FORMAT(_not9,"General Number"))) return _startOfNumResult:
Please refer to the attachment below for details
Hope this helps.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
not clear about your request. What's the expected output?
- gauravnarchal5 years agoPost Prodigy
hI ryan_mayu
Requirement
If the Serialnumber starts with 9 then
Calculate Datediff between returndate (Substract [-]) Shipdate and then Multiply (*) with number of items (NumberOfItems)
else
Calculate Datediff between Shipdate (Substract [-]) returndate and then Multiply (*) with number of items (NumberOfItems)
else
return "Error" (For any nonconverted values)
DATA
Table1
SerialID SerialNumber 894482 793054 896868 795251 903783 800600 910030 905390 910802 906090 912014 907243 912764 808136 912763 908178 915263 ERDEFAULT 917763 90LKTLRW 920263 LIU09PLM 922763 "NJK9800 Table2
SerialID Shipdate returndate NumberOfItems 894482 10-Jan-21 30-Jan-21 1 896868 3-Feb-21 5-Feb-21 2 903783 27-Mar-21 11-May-21 1 910030 30-Apr-21 29-May-21 1 910802 29-May-21 29-May-21 1 912014 30-May-21 29-Jun-21 5 912764 6-Jun-21 12-Jun-21 2 912763 6-Jun-21 12-Jun-21 6 915263 11-Jun-21 17-Jun-21 1 917763 16-Jun-21 22-Jun-21 1 920263 21-Jun-21 27-Jun-21 5 922763 26-Jun-21 2-Jul-21 1 RESULT
Table 2 & Visual should be as below
SerialID Shipdate returndate NumberOfItems Days (Result) SerialNumber 894482 10-Jan-21 30-Jan-21 1 20 793054 896868 3-Feb-21 5-Feb-21 2 2 795251 903783 27-Mar-21 11-May-21 1 45 800600 910030 30-Apr-21 29-May-21 1 -29 905390 910802 29-May-21 29-May-21 1 0 906090 912014 30-May-21 29-Jun-21 5 -30 907243 912764 6-Jun-21 12-Jun-21 2 6 808136 912763 6-Jun-21 12-Jun-21 6 -6 908178 915263 11-Jun-21 17-Jun-21 1 Error ERDEFAULT 917763 16-Jun-21 22-Jun-21 1 -6 90LKTLRW 920263 21-Jun-21 27-Jun-21 5 Error LIU09PLM 922763 26-Jun-21 2-Jul-21 1 Error "NJK9800 Total 2 - ryan_mayu5 years agoSuper User
Measure = if(LEFT(max(Table1[SerialNumber]),1)="9",int((max(Table2[Shipdate])-max(Table2[returndate]))),int(max(Table2[returndate])-max(Table2[Shipdate])))pls see the attachment below.
Now the question is how to identify "nonconverted values"? Any logic for this?