Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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. 

SegmentCustomerNew_Segment04.202005.2020
XAX10
YAY01
XBX11
ZCZ11
ZDZ10
XDX01

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;

SegmentCustomerNew_Segment04.202005.2020Final_Segment
XAX100
YAY01X
XBX11X
ZCZ11Z
ZDZ100
XDX01Z
  • 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's avatar
    az38
    Icon for Community Champion rankCommunity 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's avatar
    v-juanli-msft
    Icon for Community Support rankCommunity 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.