Forum Discussion
creating a new column based on different conditions
Hi, Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a measure or a calculated column as below.
Measure:
Result Measure =
var _value = SELECTEDVALUE('Table'[Value])
var _previousvalue =
CALCULATE(
SUM('Table'[Value]),
FILTER(
ALL('Table'),
'Table'[Date] = SELECTEDVALUE('Table'[Date])-1
)
)
return
SWITCH(
TRUE(),
_value<30,"Initial",
_value>60,"High",
NOT(ISBLANK(_previousvalue))&&_value>=30&&_value<=60,
IF(
_previousvalue<=_value,
"Low to High",
"High to Low"
)
)
Calculated column:
Result Column =
var _previousvalue =
CALCULATE(
SUM('Table'[Value]),
FILTER(
ALL('Table'),
'Table'[Date] = EARLIER('Table'[Date])-1
)
)
return
SWITCH(
TRUE(),
[Value]<30,"Initial",
[Value]>60,"High",
NOT(ISBLANK(_previousvalue))&&[Value]>=30&&[Value]<=60,
IF(
_previousvalue<=[Value],
"Low to High",
"High to Low"
)
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous6 years agoNot applicable
Hi v-alq-msft
Thanks for your response. I actually used your code and it runs pretty well. However, it didn't capture what exactly I needed.
below is the sample data I have working on and how it should be categorized.
Timestamp value category 02/01/2020 0:00 46.21064 High to low 02/01/2020 0:30 45.76316 High to low 02/01/2020 1:00 45.31568 High to low 02/01/2020 1:30 44.8682 High to low 02/01/2020 2:00 44.42072 High to low 02/01/2020 2:30 43.97324 High to low 02/01/2020 3:00 43.52576 High to low 02/01/2020 3:30 43.07828 High to low 02/01/2020 4:00 42.6308 High to low 02/01/2020 4:30 42.18332 High to low 02/01/2020 5:00 41.73584 High to low 02/01/2020 5:30 41.28836 High to low 02/01/2020 6:00 40.84088 High to low 02/01/2020 6:30 40.3934 High to low 02/01/2020 7:00 39.94591 Low to High 02/01/2020 7:30 39.49843 Low to High 02/01/2020 8:00 43.05095 Low to High 02/01/2020 8:30 44.62967 Low to High 02/01/2020 9:00 45.66694 Low to High 02/01/2020 9:30 47.60273 Low to High 02/01/2020 10:00 57.42029 Low to High 02/01/2020 10:30 69.13529 high 02/01/2020 11:00 89.46739 high 02/01/2020 11:30 91.17651 high 02/01/2020 12:00 90.79887 high 02/01/2020 12:30 89.40544 high 02/01/2020 13:00 90.17364 high 02/01/2020 13:30 90.41076 high 02/01/2020 14:00 89.24444 high 02/01/2020 14:30 89.76357 high 02/01/2020 15:00 84.94303 high 02/01/2020 15:30 84.94058 high 02/01/2020 16:00 85.19124 high 02/01/2020 16:30 83.77281 high 02/01/2020 17:00 84.43388 high 02/01/2020 17:30 83.00806 high 02/01/2020 18:00 84.34739 high 02/01/2020 18:30 87.4527 high 02/01/2020 19:00 89.6434 high 02/01/2020 19:30 90.1075 high 02/01/2020 20:00 89.062 high 02/01/2020 20:30 88.69436 high 02/01/2020 21:00 88.73694 high 02/01/2020 21:30 88.5727 high 02/01/2020 22:00 89.31903 high 02/01/2020 22:30 54.86937 High to low 02/01/2020 23:00 51.12762 High to low 02/01/2020 23:30 42.27404 High to low 03/01/2020 0:00 38.40974 High to low 03/01/2020 0:30 38.348 High to low 03/01/2020 1:00 38.38959 High to low 03/01/2020 1:30 38.3909 High to low 03/01/2020 2:00 38.38503 High to low 03/01/2020 2:30 38.40678 High to low 03/01/2020 3:00 38.39951 High to low 03/01/2020 3:30 38.3721 High to low 03/01/2020 4:00 38.37442 High to low 03/01/2020 4:30 38.37535 High to low 03/01/2020 5:00 48.38288 High to low 03/01/2020 5:30 48.37737 High to low 03/01/2020 6:00 48.34555 High to low 03/01/2020 6:30 48.39713 High to low 03/01/2020 7:00 48.36788 Low to High 03/01/2020 7:30 48.32486 Low to high 03/01/2020 8:00 48.31179 Low to high 03/01/2020 8:30 32.94141 Low to high 03/01/2020 9:00 46.73546 Low to high 03/01/2020 9:30 53.97904 Low to high 03/01/2020 10:00 57.83364 Low to high 03/01/2020 10:30 59.42461 Low to high 03/01/2020 11:00 59.62005 Low to high 03/01/2020 11:30 82.59748 high 03/01/2020 12:00 81.68488 high 03/01/2020 12:30 80.79855 high 03/01/2020 13:00 80.60854 high 03/01/2020 13:30 88.16503 high 03/01/2020 14:00 89.99412 high 03/01/2020 14:30 90.41641 high 03/01/2020 15:00 90.05349 high 03/01/2020 15:30 90.35498 high 03/01/2020 16:00 90.11911 high 03/01/2020 16:30 90.06745 high 03/01/2020 17:00 90.51439 high 03/01/2020 17:30 87.56244 high 03/01/2020 18:00 88.68581 high 03/01/2020 18:30 84.66999 high 03/01/2020 19:00 84.57362 high 03/01/2020 19:30 86.55887 high 03/01/2020 20:00 85.48984 high 03/01/2020 20:30 48.79817 High to low 03/01/2020 21:00 46.22248 High to low 03/01/2020 21:30 41.67118 High to low 03/01/2020 22:00 39.96584 High to low 03/01/2020 22:30 38.8306 High to low 03/01/2020 23:00 34.5612 High to low 03/01/2020 23:30 38.14033 High to low Sorry I forgot to tell that in every 7am, it should be transitioned to Low-to-high from high-to-low. So basically, from 7am it should categorized as low-to-High (30-60) until it reaches high (above 60) then it gradually ramps down (high-to-low: 60-30). approaximately 12 midnight but now always the case. The cycle should be like that. It very rare to have less than 30 actually and it might happens any time of the day and it tooks days before it function again that's way the reading is 0 or less than 30.
Do you think it possible to cofigure it that way?
thanks and godbless
regards,
ecmurillo