Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
araz_01
New Member

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
1 ACCEPTED SOLUTION
v-jtian-msft
Community Support
Community Support

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"
)

 

vjtianmsft_0-1717553230861.pngvjtianmsft_1-1717553239360.png

vjtianmsft_2-1717553246549.pngvjtianmsft_3-1717553257768.png

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.

View solution in original post

1 REPLY 1
v-jtian-msft
Community Support
Community Support

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"
)

 

vjtianmsft_0-1717553230861.pngvjtianmsft_1-1717553239360.png

vjtianmsft_2-1717553246549.pngvjtianmsft_3-1717553257768.png

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.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.