Forum Discussion
Firstnonblank rows based on another column per group
- 5 years ago
Anonymous,
Try these measures:
iscomplained calc = VAR vCurrentStatus = MAX ( Table2[status] ) VAR vValueBlankStatus = CALCULATE ( MAX ( Table2[iscomplained] ), ALLSELECTED ( Table2 ), VALUES ( Table2[customerno] ), Table2[status] = BLANK () ) VAR vMinStatusDate = CALCULATE ( MIN ( Table2[status date] ), ALLSELECTED ( Table2 ), VALUES ( Table2[customerno] ), NOT Table2[status] = BLANK () ) VAR vMinStatus = CALCULATE ( MIN ( Table2[status] ), ALLSELECTED ( Table2 ), VALUES ( Table2[customerno] ), Table2[status date] = vMinStatusDate ) VAR vResult = SWITCH ( TRUE (), ISBLANK ( vCurrentStatus ), BLANK (), IF ( NOT ISBLANK ( vValueBlankStatus ) && vCurrentStatus = vMinStatus, vValueBlankStatus, MAX ( Table2[iscomplained] ) ) ) RETURN vResult iscomplained final = SUMX ( VALUES ( Table2[customerno] ), [iscomplained calc] )
Anonymous,
Try this solution. The second measure is required in order to calculate totals. Make sure the status column contains blank where no status exists (not an empty string).
Measures:
iscomplained calc =
VAR vCurrentStatus =
MAX ( Table1[status] )
VAR vValueBlankStatus =
CALCULATE ( MAX ( Table1[iscomplained] ), ISBLANK ( Table1[status] ) )
VAR vMinStatus =
CALCULATE ( MIN ( Table1[status] ), ALLEXCEPT ( Table1, Table1[customerno] ) )
VAR vResult =
SWITCH (
TRUE (),
ISBLANK ( vCurrentStatus ), BLANK (),
IF (
NOT ISBLANK ( vValueBlankStatus )
&& vCurrentStatus = vMinStatus,
vValueBlankStatus,
MAX ( Table1[iscomplained] )
)
)
RETURN
vResult
iscomplained final =
SUMX ( VALUES ( Table1[customerno] ), [iscomplained calc] )
In the visual, set the status field to "Show items with no data":
- Anonymous5 years agoNot applicable
Hi, thanks for your reply.
How would I adapt it, in a situation where we have a "status date"?
truly appreciate your help 🙂- DataInsights5 years agoSuper User
Anonymous,
Would you be able to provide sample data that I can copy to Power BI, as well as the expected result?
- Anonymous5 years agoNot applicable
Hi again,
thanks again for the quick reply. I have attached a table with a sample data.., and also desired outcome
The idea would be that, the value of iscomplained, moves to the first non blank status, based on the earliest date. So for customer AA, the first non blank status is on 04-02-2020
Current situationcustomerno status status date iscomplained AA 01.02.2020 1 AA returned 06.02.2020 AA canceled 04.02.2020 AA processing 06.02.2020 BC sent 01.03.2020 1 CD sent 01.06.2020 GH Delivered 01.07.2020 1 Desired outcome
customerno status status date iscomplained AA 01.02.2020 AA returned 06.02.2020 AA canceled 04.02.2020 1 AA processing 06.02.2020 BC sent 01.03.2020 1 CD sent 01.06.2020 GH Delivered 01.07.2020 1 Appreciate it:)