Forum Discussion

araz_01's avatar
araz_01
New Member
2 years ago
Solved

DAX for calculated column with date variable for stacked column chart

Hi PBI Community,

 

I would like to create a calculated column (that can be used as a legend) to categorize and count the OpportunityIDs based on two date columns.

Can you please help me what is the issue with my formula based on the sample data provided?
Currently, the column can only be added to the y-axis instead of Column legend field.
(I have a separate date table created with relationships between the date columns in my main table.)

 

Thank you!

 

DAX:
BacklogFlag =
VAR MinWonDate = MIN('Date'[Date])
VAR MinTaskCompletedDate = MIN('Date'[Date])
RETURN
IF('MainTable'[WonDate] >= MinWonDate &&
'MainTable'[WonDate] < EOMONTH(MinWonDate, 1) &&
'MainTable'[TaskCompletedDate] >= MinTaskCompletedDate &&
'MainTable'[TaskCompletedDate] < EOMONTH(MinTaskCompletedDate, 1),
1, -- Assign a numerical value for "New"
IF(
'MainTable'[WonDate] < MinAwardDate &&
'MainTable'[TaskCompletedDate] >= MinPMDate &&
'MainTable'[TaskCompletedDate] < EOMONTH(MinTaskCompletedDate, 1),
2, -- Assign a numerical value for "Backlog",
BLANK()
)
)

Expected outcome is that stacked cloumn chart will show:
-April: Total 2 OpportunityIDs with only 'New' as legend.
-May: Total 3 OpportunityIDs fwith 2 from 'New' and 1 From 'Backlog' as legend.

Sample Data:

OpportunityID  WonDate  TaskCompletedDate  BacklogFlag
1  1-Apr-24  25-Apr-24  New
2  10-Apr-24  30-Apr-24  New
3  20-Apr-24  20-May-24  Completed from Backlog
4  1-May-24  25-May-24  New
5 10-May-24  27-May24  New
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi,araz_01 
    I am glad to help you.

    According to your description, you want to mark “New” for records that start and end in one month, “Backlog” for records that end in the next month, and blank for all other types.

    If my understanding is correct, you can refer to my test below

    I create a calculate column

    C_result = 
    VAR startdate ='MainTable'[WonDate]
    VAR enddate = 'MainTable'[TaskCompletedDate]
    RETURN
    IF(startdate<=enddate,
        IF(YEAR(startdate)=YEAR(enddate)&&MONTH(startdate)=MONTH(enddate),
    "New",
    IF(enddate>EOMONTH(startdate,0)&&enddate<=EOMONTH(startdate,1),"Backlog",BLANK())
        ),"error"
    )
    

     

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

    Best Regards,

    Carson Jian,

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi,araz_01 
    I am glad to help you.

    According to your description, you want to mark “New” for records that start and end in one month, “Backlog” for records that end in the next month, and blank for all other types.

    If my understanding is correct, you can refer to my test below

    I create a calculate column

    C_result = 
    VAR startdate ='MainTable'[WonDate]
    VAR enddate = 'MainTable'[TaskCompletedDate]
    RETURN
    IF(startdate<=enddate,
        IF(YEAR(startdate)=YEAR(enddate)&&MONTH(startdate)=MONTH(enddate),
    "New",
    IF(enddate>EOMONTH(startdate,0)&&enddate<=EOMONTH(startdate,1),"Backlog",BLANK())
        ),"error"
    )
    

     

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

    Best Regards,

    Carson Jian,

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.