Forum Discussion
Add colunma IF Conditional with DAX
Hello, thank you explain coo add a conditioned column using DAX.
Here is the example and the coumna C would be the DAX's response:
| ID | Year | Condition Result |
| A | 2018 | Continue |
| A | 2019 | Continue |
| A | 2020 | Continue |
| A | 2021 | Continue |
| B | 2018 | Left |
| C | 2018 | Continue |
| C | 2019 | Continue |
| C | 2020 | Continue |
| C | 2021 | Continue |
| D | 2019 | new |
| D | 2020 | left |
Thank you very much and greetings from Brisbane Australia.
Rosario.
- Anonymous4 years ago
Hi Syndicate_Admin ,
Please firstly create a new table:
New Table = VAR _all = CROSSJOIN ( VALUES ( 'Table'[ID] ), VALUES ( 'Table'[Year] ) ) VAR _t = ADDCOLUMNS ( _all, "min", CALCULATE ( MIN ( 'Table'[Year] ), FILTER ( _all, [ID] = EARLIER ( 'Table'[ID] ) ) ) ) VAR _maxYear = MAXX ( ALL ( 'Table' ), [Year] ) RETURN SELECTCOLUMNS ( FILTER ( _t, [Year] >= [min] && [Year] <= _maxYear ), "ID", [ID], "Year", [Year], "Status", LOOKUPVALUE ( 'Table'[Condition Result], [ID], [ID], [Year], [Year] ) )Then add a new column:
Final = VAR _t = SUMMARIZE ( FILTER ( 'New Table', [ID] = EARLIER ( 'New Table'[ID] ) ), [Status] ) VAR _lastYear = MAXX ( FILTER ( 'New Table', [ID] = EARLIER ( 'New Table'[ID] ) && [Status] <> BLANK () ), [Year] ) VAR _lastStatus = LOOKUPVALUE ( 'New Table'[Status], [ID], [ID], [Year], _lastYear ) RETURN IF ( [Status] = BLANK (), IF ( ( "Continue" IN _t ) = FALSE, _lastStatus ), [Status] )Final output:
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 Replies
- Samarth_18Community Champion
Hi Syndicate_Admin ,
Could you please share the conditions how that column need to calculate?
Thanks,
Samarth
- Syndicate_AdminAdministrator
Thank you Samarth for your support, from my example table I want to get column C, Condition Result
Best regards
Rosario
- AnonymousNot applicable
Hi Syndicate_Admin ,
Please firstly create a new table:
New Table = VAR _all = CROSSJOIN ( VALUES ( 'Table'[ID] ), VALUES ( 'Table'[Year] ) ) VAR _t = ADDCOLUMNS ( _all, "min", CALCULATE ( MIN ( 'Table'[Year] ), FILTER ( _all, [ID] = EARLIER ( 'Table'[ID] ) ) ) ) VAR _maxYear = MAXX ( ALL ( 'Table' ), [Year] ) RETURN SELECTCOLUMNS ( FILTER ( _t, [Year] >= [min] && [Year] <= _maxYear ), "ID", [ID], "Year", [Year], "Status", LOOKUPVALUE ( 'Table'[Condition Result], [ID], [ID], [Year], [Year] ) )Then add a new column:
Final = VAR _t = SUMMARIZE ( FILTER ( 'New Table', [ID] = EARLIER ( 'New Table'[ID] ) ), [Status] ) VAR _lastYear = MAXX ( FILTER ( 'New Table', [ID] = EARLIER ( 'New Table'[ID] ) && [Status] <> BLANK () ), [Year] ) VAR _lastStatus = LOOKUPVALUE ( 'New Table'[Status], [ID], [ID], [Year], _lastYear ) RETURN IF ( [Status] = BLANK (), IF ( ( "Continue" IN _t ) = FALSE, _lastStatus ), [Status] )Final output:
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.