Forum Discussion
New value for same dimension on another row.
Hi all,
I want to make a calculation. It doesn't matter to do it with Dax or M.
I have a dataset like as below. I have a customers. Our customers segment might change month by month.
| Segment | Customer | New_Segment | 04.2020 | 05.2020 |
| X | A | X | 1 | 0 |
| Y | A | Y | 0 | 1 |
| X | B | X | 1 | 1 |
| Z | C | Z | 1 | 1 |
| Z | D | Z | 1 | 0 |
| X | D | X | 0 | 1 |
I want to create a new column as Final_Segment
For a customer;
If columns 04.2020 and 05.2020 = 1 then Final_Segment will equal New_Segment
If column 04.2020 = 0 and 05.2020 = 1 then Final_Segment will equal New_Segment value which 04.2020 column = 1 row for same customer.
If column 04.2020 = 1 and 05.2020 = 0 then return 0
Expected output is;
| Segment | Customer | New_Segment | 04.2020 | 05.2020 | Final_Segment |
| X | A | X | 1 | 0 | 0 |
| Y | A | Y | 0 | 1 | X |
| X | B | X | 1 | 1 | X |
| Z | C | Z | 1 | 1 | Z |
| Z | D | Z | 1 | 0 | 0 |
| X | D | X | 0 | 1 | Z |
Hi Anonymous
for DAX
Final_Segment = SWITCH(TRUE(), [04.2020] = 1 && [05.2020] = 1, [New_Segment], [04.2020] = 0 && [05.2020] = 1, CALCULATE(FIRSTNONBLANK(Table[New_Segment], 1), ALLEXCEPT(Table, Table[Customer]), Table[04.2020] = 1, [04.2020] = 1 && [05.2020] = 0, 0 )Hi Anonymous
I would value az38's answer, but a little change below:
Final_Segment = SWITCH(TRUE(), [04.2020] = 1 && [05.2020] = 1, FORMAT([New_Segment],"general"), [04.2020] = 0 && [05.2020] = 1, CALCULATE(FIRSTNONBLANK('Table'[New_Segment], 1), FILTER(ALLEXCEPT('Table', 'Table'[Customer]), 'Table'[04.2020] = 1)), [04.2020] = 1 && [05.2020] = 0, "0" )Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- az38
Community Champion
Hi Anonymous
for DAX
Final_Segment = SWITCH(TRUE(), [04.2020] = 1 && [05.2020] = 1, [New_Segment], [04.2020] = 0 && [05.2020] = 1, CALCULATE(FIRSTNONBLANK(Table[New_Segment], 1), ALLEXCEPT(Table, Table[Customer]), Table[04.2020] = 1, [04.2020] = 1 && [05.2020] = 0, 0 ) - v-juanli-msft
Community Support
Hi Anonymous
I would value az38's answer, but a little change below:
Final_Segment = SWITCH(TRUE(), [04.2020] = 1 && [05.2020] = 1, FORMAT([New_Segment],"general"), [04.2020] = 0 && [05.2020] = 1, CALCULATE(FIRSTNONBLANK('Table'[New_Segment], 1), FILTER(ALLEXCEPT('Table', 'Table'[Customer]), 'Table'[04.2020] = 1)), [04.2020] = 1 && [05.2020] = 0, "0" )Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.