Forum Discussion
Select Specific Values from a row in a table based on a Date Condition
- Anonymous1 year ago
Hi mmunozjr5 , hello Bibiano_Geraldo and danextian , thank you for your prompt reply!
Based on Bibiano Geraldo's solution, please create the calculated column as shown below:
ConsecutiveMH = VAR CurrentKPI = 'Table'[KPI Name] VAR CurrentDate = 'Table'[Date] VAR PreviousMonth1 = EDATE(CurrentDate, -1) VAR PreviousMonth2 = EDATE(CurrentDate, -2) VAR NextMonth1 = EDATE(CurrentDate, 1) VAR ValueCurrent = LOOKUPVALUE('Table'[Value], 'Table'[KPI Name], CurrentKPI, 'Table'[Date], CurrentDate) VAR ValuePrevious1 = LOOKUPVALUE('Table'[Value], 'Table'[KPI Name], CurrentKPI, 'Table'[Date], PreviousMonth1) VAR ValuePrevious2 = LOOKUPVALUE('Table'[Value], 'Table'[KPI Name], CurrentKPI, 'Table'[Date], PreviousMonth2) VAR ValueNext1 = LOOKUPVALUE('Table'[Value], 'Table'[KPI Name], CurrentKPI, 'Table'[Date], NextMonth1) VAR IsConsecutiveMH = ValueCurrent IN {"M", "H"} && ValuePrevious1 IN {"M", "H"} && ValuePrevious2 IN {"M", "H"} VAR OnlyMOrBlank = CALCULATE( COUNTROWS('Table'), FILTER('Table', 'Table'[KPI Name] = CurrentKPI && ('Table'[Value] = "M" || 'Table'[Value]=BLANK())) ) = CALCULATE( COUNTROWS('Table'), FILTER('Table', 'Table'[KPI Name] = CurrentKPI) ) VAR OnlyHOrBlank = CALCULATE( COUNTROWS('Table'), FILTER('Table', 'Table'[KPI Name] = CurrentKPI && ('Table'[Value] = "H" || 'Table'[Value]=BLANK())) ) = CALCULATE( COUNTROWS('Table'), FILTER('Table', 'Table'[KPI Name] = CurrentKPI) ) VAR IsValidAfterSequence = IF( OnlyMOrBlank || OnlyHOrBlank, TRUE, NOT(ValueNext1=BLANK() || ValueNext1 = "L") ) RETURN IF( IsConsecutiveMH && IsValidAfterSequence, "Yes", "No" )Result for your reference:
Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, as danextian said, your need to Unpivot columns first off all:
1. In power query, select the columns [KPI ID] and [KPI NAME] and then with right click on top of one, go to unpivot other columns as shown bellow:
Your can lear more about Unpivot here: Unpivot columns
2. Now your data should look like this:
3. Change types and rename columns as you need, make sure that the date column is in date format:
4. Close and apply
5. In your table, create a calculated column by using the following DAX code:
ConsecutiveMH =
VAR CurrentKPI = 'Table'[KPI Name]
VAR CurrentDate = 'Table'[Date]
VAR PreviousMonth1 = EDATE(CurrentDate, -1)
VAR PreviousMonth2 = EDATE(CurrentDate, -2)
VAR ValueCurrent = LOOKUPVALUE('Table'[Value], 'Table'[KPI Name], CurrentKPI, 'Table'[Date], CurrentDate)
VAR ValuePrevious1 = LOOKUPVALUE('Table'[Value], 'Table'[KPI Name], CurrentKPI, 'Table'[Date], PreviousMonth1)
VAR ValuePrevious2 = LOOKUPVALUE('Table'[Value], 'Table'[KPI Name], CurrentKPI, 'Table'[Date], PreviousMonth2)
RETURN
IF(
ValueCurrent IN {"M", "H"} &&
ValuePrevious1 IN {"M", "H"} &&
ValuePrevious2 IN {"M", "H"},
"Yes",
"No"
)
now you can add A matrix with Kpi name column in rows field and add a slicer with created column, and this should look like this:
NOTE: Make sure to replace columns and tables names with your owns.
If this help you, please give a kudo and mark as solution.
Thank you
Hello Geraldo, thank you so much for taking the time to provide me with this solution. I am providing additional clarification to see if you could correct the issue with Average Resolution Time, and Customer Retention as based on the following rules they should not be returned on the table. Here is the additional information. THank you!
Remember, if a value other than M or H or a blank exists after any 3 consecutives month with values of M or H, then it shouldn't be counted. See KRI Name "Average resolution Time".
Business Rules
- A blank value or values after is ok as long as there is no other nonconsecutive values, so in this case Revenue Growth Rate counts
- We need exactly 3 consecutive 'M' or 'H' values.
- If there are non-'M'/'H' values (like 'L') or blanks immediately after this sequence, the KPI should be disqualified.
- Blanks after a valid 3-month sequence of 'M'/'H' are allowed as long as they don’t interrupt or add to the consecutive values.
- Here are the name of the tables and fields I am using
Column Names
- 'Monthly KPI Log'
- 'Monthly KPI Log'[KPI Name]
- 'Monthly KPI Log'[Value]
- 'Monthly KPI Log'[Metric Collection Date]