Forum Discussion
Difference in Row Values Based on Other Columns
- Anonymous4 years ago
Hi Ncf5031 ,
I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a measure as below:
Hrs Diff = VAR _selsn = SELECTEDVALUE ( 'Failures'[S/N] ) VAR _curdate = SELECTEDVALUE ( 'Failures'[date] ) VAR _predate = CALCULATE ( MAX ( 'Failures'[date] ), FILTER ( ALLSELECTED ( 'Failures' ), 'Failures'[date] < _curdate ) ) VAR _prehours = CALCULATE ( SUM ( 'Failures'[Hours] ), FILTER ( ALLSELECTED ( 'Failures' ), 'Failures'[date] = _predate ) ) RETURN IF ( ISBLANK ( _prehours ), BLANK (), SUM ( 'Failures'[Hours] ) - _prehours )If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
How to upload PBI in Community
Best Regards
- 4 years ago
Thank you all for your help! I ended up using techniques from the suggestions of both amitchandak and Anonymous.
Below is the code snippet that results in a ~mostly~ correct solution. I say mostly because Ideally I would eliminate the hours for the first failure, but it's not the end of the world if they show up. Perhaps this could be solved by using EVALUATE and START ATTime Between Failures = VAR SerialNumber = 'FAILURES'[SERIAL_NUM] VAR DT = 'FAILURES'[DATET] VAR LAST_HOURS = 'FAILURES'[HRS] RETURN LAST_HOURS - (CALCULATE(MAX('FAILURES'[HRS]), TOPN(1,FILTER('FAILURES', 'FAILURES'[SERIAL_NUM] = SerialNumber && 'FAILURES'[DATE] < DT), 'FAILURES'[DATE], DESC)))
Hi Ncf5031 ,
I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a measure as below:
Hrs Diff =
VAR _selsn =
SELECTEDVALUE ( 'Failures'[S/N] )
VAR _curdate =
SELECTEDVALUE ( 'Failures'[date] )
VAR _predate =
CALCULATE (
MAX ( 'Failures'[date] ),
FILTER ( ALLSELECTED ( 'Failures' ), 'Failures'[date] < _curdate )
)
VAR _prehours =
CALCULATE (
SUM ( 'Failures'[Hours] ),
FILTER ( ALLSELECTED ( 'Failures' ), 'Failures'[date] = _predate )
)
RETURN
IF ( ISBLANK ( _prehours ), BLANK (), SUM ( 'Failures'[Hours] ) - _prehours )
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
How to upload PBI in Community
Best Regards
Thank you all for your help! I ended up using techniques from the suggestions of both amitchandak and Anonymous.
Below is the code snippet that results in a ~mostly~ correct solution. I say mostly because Ideally I would eliminate the hours for the first failure, but it's not the end of the world if they show up. Perhaps this could be solved by using EVALUATE and START AT
Time Between Failures =
VAR SerialNumber = 'FAILURES'[SERIAL_NUM]
VAR DT = 'FAILURES'[DATET]
VAR LAST_HOURS = 'FAILURES'[HRS]
RETURN
LAST_HOURS - (CALCULATE(MAX('FAILURES'[HRS]), TOPN(1,FILTER('FAILURES', 'FAILURES'[SERIAL_NUM] = SerialNumber && 'FAILURES'[DATE] < DT), 'FAILURES'[DATE], DESC)))
- Anonymous4 years agoNot applicable
Hi Ncf5031 ,
If your problem has been resolved, could you please mark your post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours. Thank you.
Best Regards
- Ncf50314 years agoAdvocate I
Anonymous thank you for reminding me.
I ended up marking my post as the solution, though I mentioned I came to this conclusion based off of the assisatnace of you and amitchandak. I wish I could mark more than one post as a solution, but unfortunately I can't.
- Ncf50314 years agoAdvocate I
Anonymous if I would want to exclude the very first instance of a serial number (i.e.-the first failure) in order to see only the hours between failures, how could I go about that?
- Anonymous4 years agoNot applicable
Hi Ncf5031 ,
Since the [Time Between Failures] you created is a calculated column, you can do a filter on this calculated column in the table with the condition that the value of [Time Between Failures] is not blank. This way the rest is all data with hour diff...
Best Regards