T.mum
T.mum

Reputation: 85

Create column "after" in Powerbi (DAX)

I have the following information and I want to create the column "Later" From isProm : is the next day have the same value or no?

Date         isProm  Later
2018-06-06   1       1
2018-06-13   1       1
2018-08-20   1       1
2018-09-12   1       0
2018-09-12   0       0

Could you help me to do that with day please?

Thank you very much,

Ana

Upvotes: 0

Views: 28

Answers (1)

mkRabbani
mkRabbani

Reputation: 16908

Create your new Custom Column with this below code-

Option 1:

later = 

var current_row_isporm = your_table_name[isProm]
var current_row_date = your_table_name[Date]
var next_date =
CALCULATE(
    MIN(your_table_name[Date]),
    FILTER(
        ALL(your_table_name),
        your_table_name[Date] > current_row_date
    )
)

var nex_date_isporm = 
CALCULATE(
    MIN(your_table_name[isProm]),
    FILTER(
        ALL(your_table_name),
        your_table_name[Date] = next_date
    )
)

RETURN IF(current_row_isporm = nex_date_isporm,1,0)

Option 2: You can also use this below code for same output-

later = 

var current_row_isporm = your_table_name[isProm]
var current_row_date = your_table_name[Date]
var next_date_isporm =
CALCULATE(
    MINX(
        TOPN(
            1,
            FILTER(
                ALL(your_table_name),
                your_table_name[Date] > current_row_date
            ),
            your_table_name[Date].[Date],ASC
        ),
        your_table_name[isProm]
    )    
)

RETURN IF(current_row_isporm = next_date_isporm,1,0)

Here is the output. I have slightly different output because of date format in my laptop.

enter image description here

Upvotes: 0

Related Questions