Forum Discussion
SimonSchoutz
2 years agoHelper I
Conditional index column
Hello everyone, i want to add a index column with following conditions: I have 2 different columns counting upwards, first column 1 counts to from 1 to 3, while column 2 remains 0. When 3 is...
bhanu_gautam
2 years agoSuper User
SimonSchoutz , To achieve this you can use Power Query
Add an Index Column:
In the Power Query Editor, add an index column by clicking on Add Column > Index Column > From 1.
Create Custom Columns:
Create custom columns for Column 1, Column 2, and Index using the following M code.
Column1 =
let
MaxValue = 3, -- Change this to your desired maximum value
Index = [Index] - 1,
Cycle = Number.IntegerDivide(Index, MaxValue * 2),
Position = Number.Mod(Index, MaxValue * 2),
Value = if Position < MaxValue then Position + 1 else MaxValue
in
Value
Column2 =
let
MaxValue = 3, -- Change this to your desired maximum value
Index = [Index] - 1,
Cycle = Number.IntegerDivide(Index, MaxValue * 2),
Position = Number.Mod(Index, MaxValue * 2),
Value = if Position < MaxValue then 0 else Position - MaxValue + 1
in
Value
IndexColumn =
let
MaxValue = 3, -- Change this to your desired maximum value
Index = [Index] - 1,
Cycle = Number.IntegerDivide(Index, MaxValue * 2)
in
Cycle + 1
- SimonSchoutz2 years agoHelper I
EDIT:
Oh sorry, i think there was a missunderstanding on my side.
I don´t want to create column 1 and 2, they are already existing machine data.
The maximum value in column 1 and 2 can vary depending how long the machine was running.
EDIT2:
Okay, i understood, where i have to insert M-Code, but problem still exist.
I don´t want to create a new column 1 and 2, they already exist.
Here is an example of actual machine data:
2,1 154,9 7,8 154,9 12,2 154,9 16,6 154,9 21 154,9 25,4 154,9 29,9 154,9 34,3 154,9 38,7 154,9 43,1 154,9 47,5 154,9 51,9 154,9 56,3 154,9 60,7 154,9 65,1 154,9 69,5 154,9 73,9 154,9 78,3 154,9 82,7 154,9 87,1 154,9 91,5 154,9 95,9 154,9 100,3 154,9 104,7 154,9 109,1 154,9 113,4 154,9 117,9 154,9 122,3 154,9 126,7 154,9 131,1 154,9 135,5 154,9 139,9 154,9 144,3 154,9 148,7 154,9 153 154,9 154,9 2,3 154,9 6,9 154,9 11,4 154,9 15,9 154,9 20,3 154,9 24,7 154,9 29 154,9 33,5 154,9 37,8 154,9 42,3 154,9 46,6 154,9 51,2 154,9 55,6 154,9 60 154,9 64,4 154,9 68,7 154,9 73,2 154,9 77,5 154,9 82 154,9 86,3 154,9 90,8 154,9 95,2 154,9 99,6 154,9 104,1 154,9 108,4 154,9 112,9 154,9 117,2 154,9 121,7 154,9 126 154,9 130,5 154,9 134,9 154,9 139,2 154,9 143,7 154,9 148 154,9 152,5 0,3 154,6 6,6 154,6 10,9 154,6 15,4 154,6 19,9 154,6 24,2 154,6 28,7 154,6 33 154,6 37,5 154,6 41,8 154,6 46,3 154,6 50,7 154,6 55 154,6 59,4 154,6 63,8 154,6 68,3 154,6 72,6 154,6 77,1 154,6 81,4 154,6 85,9 154,6 90,3 154,6 94,6 154,6 99 154,6 103,4 154,6 107,9 154,6 112,2 154,6 116,7 154,6 121 154,6 125,4 154,6 129,8 154,6 134,1 154,6 138,6 154,6 142,9 154,6 147,4 154,6 151,7 154,6 154,8 0 154,8 5,7 154,8 10,1 154,8 14,6 154,8 18,9 154,8 23,4 154,8 27,8 154,8 32,3 154,8 36,6 154,8 41 154,8 45,5 154,8 49,8 154,8 54,3 154,8 58,6 154,8 63,1 154,8 67,5 154,8 71,9 154,8 76,3 154,8 80,7 154,8 85,1 154,8 89,5 154,8 93,9 154,8 98,3 154,8 102,7 154,8 107,1 154,8 111,5 154,8 115,9 154,8 120,3 154,8 124,7 154,8 129,1 154,8 133,5 154,8 137,9 154,8 142,3 154,8 146,7 154,8 151,1 154,8 154,5 5,4 154,5 9,8 154,5 Kind regards,
Simon