Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi All.
I have my data in Column A and B with state 1 & 0 below.
I would like to have result of Column C & D (highlighted in red) based on Column A and B state.
The result in Column C & D gives me idea on how many cycle count it have in Column A and B, as shown in Column F & G.
Other rule, the cycle count is only incremented when both Column A & B have state "0" value and the next row of either Column A or B indicates a state "1" value .
Please I will appreciate your help for any idea since I would like to apply this formula in a larger data.
Thank you in advance,
Thanks for posting an interesting problem
I created a small table like yours. I added a calculated column that added up the left and right columns. You'll see why when we get to the measure.
Since we need to access "the next row" and DAX has no built in concept of "next" or "previous" I also
added an index column in the query editor
Now we need to write the measure that calcuates whether a given row should be counted as a cycle
Is Cycle =
VAR cur_index =
SELECTEDVALUE ( Cycle[Index] )
VAR cur_both =
SELECTEDVALUE ( Cycle[leftPlusRight] )
VAR next_row_is_one =
CALCULATE (
COUNTROWS ( cycle ),
ALL ( Cycle ),
Cycle[Index] = cur_index + 1,
Cycle[leftPlusRight] > 0
)
VAR count_as_cycle = cur_both = 0
&& next_row_is_one = 1
RETURN
count_as_cycle
.We store the index value from the current filter context and the "left plus right" value as local variables. Then we use CALCULATE to count the rows where the next row has an index one greater (the next row) and a leftplusright is greater than zero (either 1 or 2)
then we return the combination of the next row being at least one and the current row being zero to say whether or not it should be counted as a cycle.
We can put this in a table graphic to check our results
This code does not calculate whether the 1 in the "next" row is in the left or right column, it could be changed to do so.
Help when you know. Ask when you don't!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
46 | |
22 | |
20 | |
15 | |
13 |
User | Count |
---|---|
49 | |
41 | |
39 | |
19 | |
19 |